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. Can anyone help me?

link|improve this question
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
feedback

migrated from stackoverflow.com Apr 10 '11 at 16:10

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

3 Answers

touch -- <filename>
rm -- <filename>

-- ends the command line switches.

link|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 ;) – STATUS_ACCESS_DENIED Apr 10 '11 at 15:29
feedback

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

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

link|improve this answer
feedback

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.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown