Thursday 9 July 2009

HOWTO: remove files older than N days

Command Syntax

find /path/to/files* -mtime +5 -exec rm {} \;

Note that there are spaces between rm, {}, and \;

Usage:
======================
Extremely useful for Miro, because it doesn't delete files unwatched. So with this command added in /usr/bin/miro, the Miro library will keep only latest videos no matter you watch it or not.

Explanation
=======================
The first argument is the path to the files. This can be a path, a directory, or a wildcard as in the example above. I would recommend using the full path, and make sure that you run the command without the exec rm to make sure you are getting the right results.
The second argument, -mtime, is used to specify the number of days old that the file is. If you enter +5, it will find files older than 5 days.

The third argument, -exec, allows you to pass in a command such as rm. The {} \; at the end is required to end the command.


Command from: http://www.howtogeek.com/howto/ubuntu/delete-files-older-than-x-days-on-linux/

No comments:

My photo
London, United Kingdom
twitter.com/zhengxin

Facebook & Twitter