Find and remove files

I regularly use the find command in scripts to clean directories on my servers.
The common way to use find to do this is to write something like:

find ./my_dir -name 'cache-*' -exec rm -rf \{\} \;

It works fine but it always outputs messages like this:

find: ./mydir/cache-001: No such file or director

which can be annoying when ran in a crontab.

I just found recently that using the option ‘-delete’ with find just fix this problem.

find ./my_dir -name 'cache-*' -delete

 

 

This entry was written by CharlyBr, posted on February 4, 2010 at 11:36 am, filed under Command line and tagged . Leave a comment or view the discussion at the permalink.