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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need a script to delete dir over 2 months old 1

Status
Not open for further replies.

jewel464g

Technical User
Jul 18, 2001
198
US
I have a huge array of folders that are automatically generated by my IDS software. I need a script that will search through these folders and delete the ones that are over 2 months old. I have written some small shell scripts, but I just don't know how to write this one. Can someone be of some assistance?? Linux platform

thanks,
Jewel When faced with a decision, always ask, 'Which would be the most fun?'
 
Sounds like a perfect job for find.
Code:
find /starting/directory/ -type d -mtime +60 -exec rm -r {} \;
But try it first with the -print instead of the -exec rm -r {} \; so that you can verify what you are deleting.

Always test and double test with any script that deletes files. You never know. Einstein47
(How come we never see the headline, "Psychic Wins Lottery"?)
 
When I run the find with -print. It's prints the correct list of directories.

But when I try it with the "-exec rm -r {} \;" it prints these error messages to the screen.



find: /var/log/snort/216.102.242.172: No such file or directory
find: /var/log/snort/218.20.63.40: No such file or directory
find: /var/log/snort/166.102.82.212: No such file or directory
find: /var/log/snort/63.57.219.185: No such file or directory
find: /var/log/snort/67.232.128.8: No such file or directory
find: /var/log/snort/61.222.90.18: No such file or directory
find: /var/log/snort/63.39.238.234: No such file or directory
find: /var/log/snort/165.121.61.133: No such file or directory
find: /var/log/snort/216.128.170.224: No such file or directory
find: /var/log/snort/216.67.212.191: No such file or directory
find: /var/log/snort/209.86.73.208: No such file or directory
find: /var/log/snort/66.168.210.30: No such file or directory
find: /var/log/snort/65.82.198.12: No such file or directory
find: /var/log/snort/209.52.98.181: No such file or directory
find: /var/log/snort/208.248.64.59: No such file or directory
find: /var/log/snort/63.163.51.3: No such file or directory
find: /var/log/snort/209.215.51.85: No such file or directory When faced with a decision, always ask, 'Which would be the most fun?'
 
fixed it by adding a *

find /starting/directory/ -type d -mtime +60 -exec rm -r {} \;
Thanks for your help,
Jessica When faced with a decision, always ask, 'Which would be the most fun?'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top