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