How do I remove a file whose name begins with a "-" ?


  

Normally a dash "-" indicates a start of flag(s)/option(s) to a command, i.e., "ls -al." Problem is that you can also [accidently] name a file beginning with a dash, let's say, "-abc.txt." In this case, normal "rm" command won't delete this file when you type "rm -abc.txt" since "rm" command sees and treats "-abc.txt" as a flag(s)/option(s) to the "rm" command.

To delete such files, figure out some way to name the file so that it doesn't begin with a dash. The simplest answer is to use

$ rm ./-filename

(assuming "-filename" is in the current directory, of course) This method of avoiding the interpretation of the "-" works with other commands too.

Alternative is that many commands accept a "- -" argument which means "this is the last option, anything after this is not an option." Give a try following;

$ rm -- -filename