Operating System - HP-UX
1832345 Members
2342 Online
110041 Solutions
New Discussion

How to find all files older than a certain date

 
SOLVED
Go to solution
Byron Myers
Trusted Contributor

How to find all files older than a certain date

I searched the forum for this answer, but got no hits (UNIX). How do I search a directory tree for all files older than a certain date, say 11/15/04 (where a file's date is that which shows up in "ls -ltr")?
If you can focus your eyes far and straight enough ahead of yourself, you can see the back of your head.
4 REPLIES 4
Pete Randall
Outstanding Contributor
Solution

Re: How to find all files older than a certain date

touch a file first:

touch /tmp/reference 20041115

then use find

find /starting_directory ! -newer /tmp/reference


Pete

Pete
Jeff Schussele
Honored Contributor

Re: How to find all files older than a certain date

Hi Byron,

You just need to calculate the number of days between then & now and construct a find command like the following:

find /top_level_dir \( -type f -a -mtime 54 \)

the -a is a logical and operator & the parens must be commented in the command and must be seperated from the values by a space. Of course you can follow that with whatever else you might need - like an exec to run something - but if there's nothing further it'll just send to std out which of course could be redirected to a file.

HTH,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
Byron Myers
Trusted Contributor

Re: How to find all files older than a certain date

I used Jeff's command - it worked like a charm (this seemed easiest to me)!
If you can focus your eyes far and straight enough ahead of yourself, you can see the back of your head.
Pete Randall
Outstanding Contributor

Re: How to find all files older than a certain date

It's easier, other than having to do the math!

Glad to help.


Pete

Pete