Find Syntax

Adam Nealis adamnealis at yahoo.co.uk
Mon Jan 2 09:15:06 PST 2006


--- Drew Tomlinson <drew at mykitchentable.net> wrote:

> On 1/2/2006 8:37 AM Kevin Brunelle said the following:
> 
> >On Monday 02 January 2006 11:19, Drew Tomlinson wrote:
> >  
> >
> >>I'm trying to find all files with a modification time older than three
> >>weeks ago.  In reading the find man page and searching Google, it seems
> >>the time returned by 'ls -l' is mtime.  Thus I construct the following
> >>command:
> >>
> >>find . -not \( -newermt 3w \) -exec ls -l {} \;
> >>
> >>But it returns files that are newer:
> >>
> >>-rw-------  1 nobody  nobody  35292 Dec 29 08:43 totContactedRcvdPeers.rrd
> >>-rw-------  1 nobody  nobody  35292 Dec 29 08:43 totContactedSentPeers.rrd
> >>-rw-------  1 nobody  nobody  35292 Dec 29 08:33
> >>./dc0/hosts/207/106/6/90/pktSent.rrd
> >>
> >>I've tried various placement of the '-not' and the )'s but I can't get
> >>it right.  What am I missing?
> >>    
> >>
> >
> >Have you tried
> >
> >find . -mtime +3w
> >
> >I don't know about the other syntax but this is what I find to be the 
> >simplest.
> >  
> >
> 
> Thanks for your reply.  I tried your syntax as:
> 
> find . -mtime +3w -exec ls -l {} \;
> 
> It returned nothing as I expected.  But then reduced it to one week as:
> 
> find . -mtime +1w -exec ls -l {} \;
> 
> which didn't seem to work because these (amongst many others) were returned:
> 
> drwx------  2 nobody  nobody  512 Dec 27 14:03 102
> total 2
> drwx------  3 nobody  nobody  512 Dec 26 08:03 9
> total 2
> drwx------  2 nobody  nobody  512 Dec 26 08:03 7
> total 432
> -rw-------  1 nobody  nobody  35292 Jan  2 07:41 bytesRcvd.rrd
> -rw-------  1 nobody  nobody  35292 Jan  2 07:41 bytesRcvdLoc.rrd
> -rw-------  1 nobody  nobody  35292 Jan  2 07:41 bytesSent.rrd
> 
> Any ideas why this might be?

if you do

ls -l /a/directory/name

you get directory contents. Is it possible that your "-exec ls -l {} \;"
is listing directory contents? To see what I mean, compare these commands:

cd /usr/ports/arabic
find . -exec ls -l {} \;|wc
     121     991    6569
find . -exec ls -ld {} \;|wc
      61     549    3942
find . -ls | wc
      61     671    6617

If you only want files, and you really have to use -exec ls, you can do

find . -type f -mtime +1w -exec ls -l {} \;


	
		
__________________________________ 
Yahoo! for Good - Make a difference this year. 
http://brand.yahoo.com/cybergivingweek2005/


More information about the freebsd-questions mailing list