Operating System - HP-UX
1834000 Members
1773 Online
110063 Solutions
New Discussion

Re: Deleting multiple files by date stamp

 
SOLVED
Go to solution
Morris Makuch
Advisor

Deleting multiple files by date stamp

Hello. I have hundreds of files in a directory that I don't need any more. But I only want to delete the files that are older than 90 days. Is there a easy way of doing this in one command? Thanks
3 REPLIES 3
Rodney Hills
Honored Contributor

Re: Deleting multiple files by date stamp

I would do the following

find /path -mtime +90 -print >/tmp/oldfiles
more /tmp/oldfiles

After examining the list, I would then remove them by-

cat /tmp/oldfiles | xargs rm

HTH

-- Rod Hills
There be dragons...
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Deleting multiple files by date stamp

cd to dir
find . -mtime +90 -exec rm {} \;

You may want to restrict it to just regular files as well:
find . -type f -mtime +90 -exec rm {} \;

It's always a good idea to restrict the -exec command to a "safe" comand until you are confident that you have the command filtered/restricted enough:

e.g. -exec ls {} \;

Man find for details and more examples.
If it ain't broke, I can fix that.
Marvin Strong
Honored Contributor

Re: Deleting multiple files by date stamp

as the others stated.

find /path -type f -mtime +90 | xargs rm