1827445 Members
6286 Online
109965 Solutions
New Discussion

problem about "find"

 
lin.chen
Frequent Advisor

problem about "find"

I use following command to find the file which has been modified during last 30 days.
find /u1/pucka/cap/4gl -mtime -30 -exec ls -l {} \;
But I failed.because I found some files are in 2004.
How can I fix this issue.
Louis,chenlin
6 REPLIES 6
Shrikant Lavhate
Esteemed Contributor

Re: problem about "find"

try

find /u1/pucka/cap/4gl -mtime -30 -exec ls -l {} +
Will it remain a personal, if I broadcast it here!
Kapil Jha
Honored Contributor

Re: problem about "find"

use 30 instead of -30

find /u1/pucka/cap/4gl -mtime 30 -exec ls -l {} \;


hope this help....
otherwise RTFM....
man find

BR,
Kapil
I am in this small bowl, I wane see the real world......
Dennis Handly
Acclaimed Contributor

Re: problem about "find"

>But I failed because I found some files are in 2004. How can I fix this issue?

Your find will find directories and those could have those 2004 files. So do:
$ find /u1/pucka/cap/4gl -mtime -30 -exec ll -d {} +
Dennis Handly
Acclaimed Contributor

Re: problem about "find"

>Kapil: use 30 instead of -30

I suggest you check again. The word problem that uses "last N days" would mean some time between today - N and today. find(1) says:
-n means less than n
john korterman
Honored Contributor

Re: problem about "find"

Hi,

you could try something like this:

$ find /u1/pucka/cap/4gl -type f -mtime -30 -exec ls -l {} \;

regards,
John K.
it would be nice if you always got a second chance
James R. Ferguson
Acclaimed Contributor

Re: problem about "find"

Hi:

You made a classis mistake. If you truly only want FILES then you need to specify that restriction:

# find /u1/pucka/cap/4gl -type f -mtime -30 -exec ls -l {} \;

Otherwise, as 'find' descends the starting path you will do an 'ls' on DIRECTORIES that have been modified within the last 30-days and may indeed report FILES in those directories that have been modified in more or less than that time you specified.

If you want DIRECTORIES that have been modified during the last 30-days, then you would do:

# find /u1/pucka/cap/4gl -type d -mtime -30 -exec ls -ld {} \;

Note, too, that in this case, we add the '-d' switch to the 'ls' argument that we want 'find' to execute to _restrict_ 'ls' to examining only the directory.

Lastly, if you are running 11.11 or later (I hope), better performance (less spawned tasks) will occur if you change the '\;' terminator to a "+". This bundles multiple arguments together instead of forking on 'ls' for each argument. See the 'find' manpages for details.

Regards!

...JRF...