File check before delete

07 March 2008   1 comment   Linux

Mind That Age!

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

Powered by Fusion×

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
Thank you for posting a comment

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:
A neat trick to zip a git repo with a version number 01 September 2017
And bash basics 16 October 2015
set -ex - The most useful bash trick of the year 31 August 2014
How I do deployments 16 December 2013
Bash tip of the day: ff 25 March 2011
Related by Text:
HTML entity fixer 25 November 2004
C++ templates or not 18 February 2004
SVN + ./todo + crontab 20 May 2006
parametrize_url() adding parameters to URLs 14 January 2005
Fastest way to find out if a file exists in S3 (with boto3) 16 June 2017