Archive

Posts Tagged ‘priority’

Be careful when using find with the delete flag to clean old files.

January 9th, 2012 3 comments

The linux find command is very powerful. I use it all the time, either manually or in cron scripts to delete useless Thumbs.db files for example. A word of caution however, if you intend on using the -delete flag with find (instead of -exec rm… or xargs etc.).

This is very bad:

find / -delete -type f -name 'Thumbs.db' -mtime +7

This is good:

find / -type f -name 'Thumbs.db' -mtime +7 -delete

The order of the -delete flag is very important. In the first case find will delete everything it finds (totally ignoring the subsequent criteria), whereas the second case will delete what is matched.

In other words, the order of the find flags/parameters/actions are very important. If you are in doubt, or even if you are not, you should always have a backup in case something goes wrong.
Read more…