4

An application created a directory called "-123456" in my /tmp directory.

In Bash, rm -rf * returns: bash: cd: -7: invalid option

rm -rf "-123456" Same thing.

Help?

3
  • Don't let this happen! What is the application? Apr 6, 2010 at 9:33
  • @Charles Stewart: Something proprietary from IBM; I can't prevent it.
    – Dean J
    Apr 27, 2010 at 16:06
  • You might think of filing a bug report to IBM about this: this is something like bedwetting. Apr 28, 2010 at 11:23

3 Answers 3

10

Use "--" to end your list of arguments. Thus: rm -rf -- -123456

7

Have you tried rm -rf ./-123456?

Edit: Works for me

# ls -l
total 1
drwxr-xr-x 2 root root 4096 Mar 29 20:48 -test
# rm -rf ./-test
# ls -l
total 0
3
  • You're right as well. Two paths to the same thing.
    – Bill Weiss
    Mar 29, 2010 at 21:04
  • However! What if the file was named "something -12345"? :)
    – Bill Weiss
    Mar 30, 2010 at 16:39
  • Easy (Sorry, can't format comments very well): $ touch something\ -12345 $ ls so* something -12345 $ rm something\ -12345 $ ls so* ls: so*: No such file or directory
    – Bryan
    Mar 31, 2010 at 6:55
-1

Classic basic UNIX puzzle. A more obtuse approach that manages to drag perl into it:

perl -e 'unlink "-12345"'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .