Accueil > Système > Delete files by creation date

Delete files by creation date

25/05/2015 Categories: Système Tags: ,

source: http://ubuntuforums.org/showthread.php?t=625132
On the command line, you can use the « find » command to select certain files, and then use the « -exec » switch to cause some other command to be run on those files. So if you use « -exec rm » you will delete the files that are found. So, for example:

Code:
 find -mmin +4 -exec rm {} +

will delete any files in the current directory (and sub-directories) that are older than 4 minutes. This is because the « -mmin +4 » switch causes find to return files older than 4 minutes. There are other options, like « -mtime » that return files based on modified date in days. You can use + or – depending on what kind of behavior you are trying to achieve. For a more complete explanation of all the options, see the manual page:
http://unixhelp.ed.ac.uk/CGI/man-cgi?find

Be careful when using the rm command! It’s usually a good idea to test your command first, before using it. So, for instance, use something like:

Code:
 find -mmin +4 -exec ls {} +

which will just list the files that you are selecting for. If the list looks right, then you can switch the « ls » to « rm » in the command and it will delete the files.

Print Friendly, PDF & Email

Related Post

Categories: Système Tags: ,
Les commentaires sont fermés.