Operating System - HP-UX
1822895 Members
3469 Online
109645 Solutions
New Discussion юеВ

find older files in a folder by specific date

 
SOLVED
Go to solution
Md. Shafiullah
Advisor

find older files in a folder by specific date

Dear All,

I have a folder and sub folder, where there are more than 1000 files. The oldest file is one year old. I want to delete files that are more than 6 months old.

1) How can i find those files?
2) How can i delete those files?

Please help.

Regards
Shafi
3 REPLIES 3
Peter Godron
Honored Contributor
Solution

Re: find older files in a folder by specific date

Shafi,
how about:
find /dir -xdev -ctime +183 -type f -exec rm {} \;

But, I would recommend running the command below FIRST, to check the list of files that will be removed:

find /dir -xdev -ctime +183 -type f -exec ls -l {} \;

/dir would be the location of the directories.
Please read "man find" for further info.

Please also read:
http://forums1.itrc.hp.com/service/forums/helptips.do?#33 on how to reward any useful answers given to your questions.

SAJ_3
New Member

Re: find older files in a folder by specific date

Hi Shafi,

Try this command ,this will list the oldfile modified before 186 days.

find -mtime +186 -exec ll {} \;




Md. Shafiullah
Advisor

Re: find older files in a folder by specific date

Dear all,

Thanks for your help. I actually found the following commands very usefull.

find ./ ! -newer /tmp/timeref -exec ls {}\;

Here /tmp/timeref file is the reference file which has the time stamp.