Linux - Deleting a file containing special characters

Ask a question

If the file you want to delete a character starting with "minus" (-), the rm command consider the following as part of the command line.
  • To remedy this, one solution is to precede the filename of the command "--", indicating rm that there are more options beyond this:
    • rm -- -name-of-file-to-be-deleted
  • A second solution is to escape the character "-" by preceding it with a backslash:
    • rm \-name-of-file-to-be-deleted
  • A final solution is to give the full path or relative path beginning with. / and having the filename in quotes:
    • rm ./"-name-of-file-to-be-deleted"

Thanks to Jeff for this tip.
Jean-François Pillou

CCM is a leading international tech website. Our content is written in collaboration with IT experts, under the direction of Jeff Pillou, founder of CCM reaches more than 50 million unique visitors per month and is available in 11 languages.

Learn more about the CCM team