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

Comments

ivo

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

Your email will never ever be published.

Previous:
"Confessions of a College Callgirl" is the new "My Secret Life As A Prostitute" March 2, 2008 Misc. links
Next:
See you at PyCon 2008 March 11, 2008 Python
Related by category:
set -ex - The most useful bash trick of the year August 31, 2014 Linux
brotli_static in Nginx November 8, 2024 Linux
Be very careful with your add_header in Nginx! You might make your site insecure February 11, 2018 Linux
Linux tip: du --max-depth=1 September 27, 2007 Linux
Related by keyword:
set -ex - The most useful bash trick of the year August 31, 2014 Linux
How to intercept and react to non-zero exits in bash February 23, 2023 Bash, GitHub
Run something forever in bash until you want to stop it February 13, 2018 Linux
How to count the most common lines in a file October 7, 2022 Linux, Bash, macOS