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 derfloh 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 all folders 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??

thanks,
Jewel When faced with a decision, always ask, 'Which would be the most fun?'
 
I'm not in front of a Linux machine to test this out right now, but a command similar to this should do it...

find /opt -type d -atime +60 -exec `rm -fr` {} \;

This command assumes that the directories that you want to delete are under /opt. Don't run this command without editing the starting point first.

Let me test this command tomorrow when I'm in front of a Linux machine. It may need some touching up.

Tell us the names of the directories you want to delete and the full path to them.


ChrisP If someone's post was helpful to you, please click the box "Click here to mark this post as a helpful or expert post".
 
Chris is quite correct. I'd only add that as a precaution you should do the find with a -print option before you do the rm, just to check that you're picking up the directories you think you are. Cheers.
 
just a syntax question for the find command...

what does the {} \; do or represent?
 
thanks Ken.

When you use the find command with the -exec option, the {} is replaced by the find results and must be terminated with a \;

For example, lets say we do a find command and the results are for a few files called file1, file2, file3, and so on. When you use the -exec option, those files (file1, file2, file3...) are what go in the {}. If I say `rm -fr` {}, its the same as `rm -fr file1 file2 file3`.

The -exec option must always be terminated with a \;

ChrisP If someone's post was helpful to you, please click the box "Click here to mark this post as a helpful or expert post".
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top