Linux - Deleting a file containing special characters

July 2017



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.

Related


Published by jak58. Latest update on April 10, 2012 at 01:01 PM by jak58.
This document, titled "Linux - Deleting a file containing special characters," is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (ccm.net).