Removing files of certain date

         ·

To remove files depending on a certain date on Linux, Unix and OSX (and I presume using Cygwin on Windows) you can use the find command and get it to execute the rm command.

find . -atime +1 -exec rm {} \;

Will send all files in the current directory that are older than one day to the remove command. Its probably best to test it by looking at the files first:

find . -atime +1 -exec ls {} \;

That will show all the files that are over a day old. The remove command is of course useful for cleaning up log file directories from a cron job when daemons or programs running don’t clean up after themselves.

comments powered by Disqus