Deleting a file, the name of which starts with a hyphen (Linux)

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 the following – if for instance your current working directory is the one containing the file in question

rm -rf ./-file