Accueil > Système > Delete files by creation date

Delete files by creation date

04/03/2024 Categories: Système Tags: ,
Print Friendly, PDF & Email

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:

 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:

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:

 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.

Lire aussi:  How to restart Gnome Panel
Categories: Système Tags: ,
Les commentaires sont fermés.