Deleting a file starting with a hypen on Linux

Posted on 2nd May 2011 in Linux, Tips & Tricks

You might have come across a difficulty in deleting a file in Linux whose name starts with a dash/hyphen.

Adding an escape character (e.g. rm -rf \-filename) or quoting the file name (e.g. rm -rf “-filename”) will not do the job.

The solution is simple: explicitly provide the full or relative path to the file. e.g.:

rm -rf /path/to/-file

or: rm -rf ./-file (if for instance your current working directory is the one containing the file in question).

comments: 0 »

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Comment

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>