Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question

migrated from stackoverflow.com 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
add comment

4 Answers 4

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
add comment

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
add comment

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
add comment
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.