File check before delete

07 March 2008   1 comment   Linux

Mind That Age!

This blog post is 10 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

Comments

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

Your email will never ever be published


Related posts

Previous:
"Confessions of a College Callgirl" is the new "My Secret Life As A Prostitute" 02 March 2008
Next:
See you at PyCon 2008 11 March 2008
Related by Keyword:
How to NOT start two servers on the same port 11 June 2018
How I found out where a bash alias was set up 09 May 2018
Run something forever in bash until you want to stop it 13 February 2018
A neat trick to zip a git repo with a version number 01 September 2017
And bash basics 16 October 2015
Related by Text:
jQuery and Highslide JS 08 January 2008
I'm back! Peterbe.com has been renewed 05 June 2005
Anti-McCain propaganda videos 12 August 2008
Ever wondered how much $87 Billion is? 04 November 2003
Guake, not Yakuake or Yeahconsole 23 January 2010