Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Possible Duplicates:
How do I delete a file named "-p" from bash?
How to delete file with this name on linux: -]???????q
Removing "-rf" file in Unix

I've accidentally created a file called: -d

I've tried using single and double quote marks as well as wild cards to remove it but every time "rm" gives me this error:

Warning: --directory (-d) option is undocumented and no-op. Use -rf for deleting non-empty dirs rm: missing operand Try `rm --help' for more information.

How do I get rid of the file?

share|improve this question

migrated from Sep 8 '11 at 20:27

This question came from our site for professional and enthusiast programmers.

marked as duplicate by slhck, grawity, sblair, Gilles, Tom Wijsman Sep 8 '11 at 23:44

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

up vote 44 down vote accepted
rm -- -d

-- means "end of options". Anything further on the command line following this is interpreted as an argument (i.e. the file name in your case), and not an option.

share|improve this answer
Never knew about that trick. Thanks! – phileas fogg Sep 8 '11 at 20:45
rm ./-d

is the answer to your question.

share|improve this answer
rm -- -d works also – Ulrich Dangel Sep 8 '11 at 20:28
This is the best solution – gd1 Sep 8 '11 at 21:03

Using '--' is by far the easiest in this specific case. However, a more general solution if you stumble across a file with unprintable control characters is to reference the file by inode:

% ls -ali aFileWithFunnyCharacters
      9215 -rw-r-----   1 chris  chris         0 Sep  8 16:55 aFileWithFunnyCharacters
% find . -xdev -inum 9215 -exec rm {} \;
% ls -ali aFileWithFunnyCharacters
aFileWithFunnyCharacters: No such file or directory
share|improve this answer

Gnu-find has a -delete option:

find -name "-d" -delete

else you could try

find -name "-d" -exec rm {} ";" 

but the -- -solution from above is shorter, and the way to stop interpretation of flags with -- is used by many programs, using the getopt-library, so learning it is a useful thing in general.

But find/-delete is something very useful to learn too. Note that both examples will delete files of name "-d" recursively, which might not happen often, but if you happen to have one file, named "-d", you might have more of them. :)

share|improve this answer

Not the answer you're looking for? Browse other questions tagged .