Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleting files older than....

Status
Not open for further replies.

snooperx

Technical User
Jul 4, 2001
15
0
0
BR
Hello all!

I´m wondering if someone could provide a script that would sweep files off the /tmp dir only when they´re older than 30 days!

Thanks for any help.

Jeffo.
 
To check it works, by printing out what it finds
Code:
find /tmp -mtime -30 -print

To actually delete stuff
Code:
find /tmp -mtime -30 -exec rm -f {} \;
 
Allright Salem.

Thanks for the hints. I'll try it out tomorrow.

I'll be using this on an AIX and HP-UX machines if it works.

[ ]s!
Jeffo.
 
Uh-oh...seems that the first command is listing ALL files on /tmp, even those that I just touched....

Any hints??
 
Jeffo,

the -mtime -30

should be

-mtime +30

to give you files over 30 days old.

Just a typo, I think. HTH.
 
Allright, it worked great, thanks!

[ ]s.
 
If you have a lot of old files, this can run faster:
Code:
find /tmp -mtime +30 -print | xargs rm -f

Hope This Help
PH.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top