Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I've got a file called -T on my linux box, and, I thought I could do

 rm "-T"

or

 rm "\-T"

or

 rm \-T

or

 rm *T

Alas, I've run out of simple tricks (or I'm misuing them).

I keep getting the error message:

rm: invalid option -- T

I'm pretty sure I could delete this file with some FTP client, but that feels like cheating. Can someone point me in the right direction?

share|improve this question
1  
The reason that all your variations on rm didn't work is because bash was expanding them to 'rm -T'. So you would consistently get rm called with '-T'. –  Kevin M Jul 8 '09 at 18:26

6 Answers 6

up vote 14 down vote accepted

A lot of *nix commands have a '--' option, which means "this is where the options end, anything from here onwards that looks like an option, isn't".

rm -- -filename

Not 100% sure if rm supports that, I'm a bit rusty.

share|improve this answer
    
Nice touch, I was curious whether this would work on other commands. –  altCognito Jul 8 '09 at 17:35

Use the "--" option to tell rm that there are no more options coming.

 rm -- -T

You can also put a "./" in front of the file like this:

 rm ./-T

As a third option, you can often use a graphic file viewer and drag it into the trash.

share|improve this answer
    
This worked for me. –  altCognito Jul 8 '09 at 17:31

Try prefixing your file with ./ I think this works.

share|improve this answer
1  
Just for giggles I tried this and it worked as well. –  altCognito Jul 8 '09 at 17:32

I just had to try:

gw:~/kana # rm -T
rm: invalid option -- 'T'
Try `rm ./-T' to remove the file `-T'.
Try `rm --help' for more information.
gw:~/kana # rm ./-T
share|improve this answer
    
Interesting, I wonder which distro did that for you. Nice touch. –  altCognito Jul 8 '09 at 17:33
    
opensuse 11.0, coreutils-6.11-9.1 Actually, even rm --help said how to do it. :) –  Marie Fischer Jul 8 '09 at 17:36
    
Ubuntu 9.04, coreutils-6.10 gave the same message. –  Dennis Williamson Jul 9 '09 at 1:42

Well, back in the day you could use ls -il or stat to print out the inode of the file then use find with an -inode flag and use -exec to call rm on that file!

I guess the post-early 90's are still calling me...... :)

share|improve this answer

Put the current directory in front of the file name, which will prevent the program from thinking you're passing it a parameter.

$ rm ./-T

-Kevin

share|improve this answer

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.