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.
Source : http://www.linuxquestions.org/questions/linux-general-1/shell-script-to-remove-old-files-based-on-date-7368/
I wanted to find the file which has not been modified(untouch) for more than 30days and list it out for me.
find /usr1 -mtime +60 -type f -exec ls -l {} \;
so, if you want to find the file has been modified within 10 days just modify mtime value
find /usr1 -mtime -10 -type f -exec ls -l {} \;
Leave a Reply