Thursday, November 26, 2009

Suppress rm No such file or directory

rm: cannot remove `*.html': No such file or directory

If you have a cron job that deletes files daily or on another schedule you probably don't want to get the email that tells you something like that. There's always the option of redirecting the output to /dev/null but then you're screwed if there's any other errors that you actually want to know about.

Instead, use the -f or --force flag of the rm program. That flag literally means ignore nonexistent files, never prompt. So instead of getting that cannot remove error, it will just go about business as usual.

Instead of the following to delete two types of files,
rm /path/to/*.html; rm /path/to/*.html.gz

Use the following to delete them and not have to worry if one type doesn't exist.
rm -f /path/to/*.html; rm -f /path/to/*.html.gz

1 comment:

Anonymous said...

Thanks, this helped me with the same issue.
Cheers, Matt