Wednesday, October 04, 2006

 

Remiving files/folders based on date

Look at the manpage for the "find" command. Here is an example of what you want.

find /var/log -mtime +60 -type f -exec rm -rf {} \;
This command will do a search in /var/log for all files that were last modified 60 or more days ago and executes a recursive forced (-rf) remove (rm). The "{}" (curly braces) is the place holder for exec to use where it will put the name of the file, and the "\;" tells exec that's the end of the statement. Find is very powerful, and I suggest you do some reading BEFORE you do any removing using "find". Also, as a test you can replace the "rm -rf" with "ls -la" to get a list of all the files that would be removed. And, if you want to remove files with specific names or extensions use the "-name" argument.

Comments: Post a Comment



<< Home

This page is powered by Blogger. Isn't yours?