5

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.

1
  • 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, 2011 at 16:14

4 Answers 4

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

-- ends the command line switches.

2
  • -f is not really necessary here. Apr 10, 2011 at 15:28
  • @Martinho: fair point. Removed it. It's more of a habit, I guess ;) Apr 10, 2011 at 15:29
5

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

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

1
  • The advantage is this working on any system, including MacOS X. Jul 26, 2012 at 17:45
0

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.

0

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

You must log in to answer this question.