Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Oddest thing I've seen!' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Oddest thing I've seen!
Authored by: dzurn on Oct 14, '02 05:31:21PM

This has to be the oddest *nix tip I've seen yet. It took me a while, then I read closely to find that the "rm *" is expanded to "rm file1 file2..." so the file named "-i" will act as a command switch when the expanded command is finally executed.

It seems to me that this tip would generalize to any command with a "*" wildcard. So if you had a file named "-rf" and you typed "rm -i *" would it override the "-i" and remove everything without interaction? Volunteers? I would never have imagined that file names can add switches to commands. Something new every day....



[ Reply to This | # ]
yikes
Authored by: jpkelly on Oct 14, '02 10:45:32PM

I once created a directory by accident thaat began with a "-" I could not delete the #%@$ thing!
Short of gasoline and a match I was tearing my hair out trying to get rid of it.
(not to mention I was trying to impress my roomate with my unix skills on his machine)
I forget what I did to get rid of it.
Perhaps I booted into 9 and trashed it.



[ Reply to This | # ]
deleting a file starting with a hyphen
Authored by: colin on Oct 15, '02 05:43:44AM

the command to remove a file starting with a hyphen is 'rm -- file' the -- switches off the flags so that the filename you type is treated as a filename rather than a switch.



[ Reply to This | # ]
deleting a file starting with a hyphen
Authored by: hayne on Oct 15, '02 10:01:55AM

An easier way (also useful for deleting files with spaces in their names, etc.) is to put the filename in double-quotes. For example:
rm "-i"
would remove the file which is the subject of this hint.



[ Reply to This | # ]
deleting a file starting with a hyphen
Authored by: SeanAhern on Oct 15, '02 03:33:05PM

Nope, that wouldn't work. All the quotes would do is tell the shell that -i is one word. To the rm binary, "-i" and -i look the same.

Believe me, I've tried stuff like this before.

Other ways to do it, though:

rm ./-i
rm -- -i



[ Reply to This | # ]