File check before delete

7 March 2008   1 comment   Linux

Mind that age!

This blog post is 14 years old! Most likely, its content is outdated. Especially if it's technical.

Because I always forget, here's how to check if a file exists before attempting to delete it in bash:

[ -f foobar.html ] && rm foobar.html

If you don't do it this way and the file doesn't exist you get this:

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



rm -f foobar.html will not complain if the file doesn't exist

Your email will never ever be published.

Related posts