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

How would you create and then delete a file that begins with the symbol "-"? Try it.

I can't write the command for this question and I don't why.

share|improve this question

migrated from Apr 10 '11 at 16:10

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

You should think about your career or education choices. The answer to your previous question is perfectly applicable here. Transfer of learning is an important ability. – Daniel Beck Apr 10 '11 at 16:14
touch -- <filename>
rm -- <filename>

-- ends the command line switches.

share|improve this answer
-f is not really necessary here. – R. Martinho Fernandes Apr 10 '11 at 15:28
@Martinho: fair point. Removed it. It's more of a habit, I guess ;) – 0xC0000022L Apr 10 '11 at 15:29

Or, without using the GNU -- convention, you can use ./:

Thus touch ./-filename and rm ./-filename

share|improve this answer
The advantage is this working on any system, including MacOS X. – Rich Homolka Jul 26 '12 at 17:45

You can use -- switch. For example rm -- -test will delete -test file.
You can also use a path of the file. For example rm ./-test will delete -test file.

share|improve this answer

The above are much easier, and you should use the './' trick (it would work on MacOSX or BSD for example), but for completeness:

Use ls -i to get the inode number, and then use find . -inum INODENUMBER -delete -print

share|improve this answer

You must log in to answer this question.