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.

  • 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
10
touch -- <filename>
rm -- <filename>

-- ends the command line switches.

  • -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
5

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

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

  • The advantage is this working on any system, including MacOS X. – Rich Homolka Jul 26 '12 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy