Re: How do you remove files with bad/wierd names
aarons@andrew.cmu.edu (Aaron Solochek) wrote:
>Marshal Kar-Cheung Wong wrote:
>> I was wondering how to remove a file by the name of --help.tgz?
>> (Don't ask...Okay if you really must know, I typed in tgz --help and I
>> get that file. There's no man page for tgz, and I think tgz shouldn't
>> accept things starting with -- as file names...) rm always takes it
>> as an option, even if quotes, double-quoted, backslashed,
>> regular-expressioned. Any suggestions?
>
>On a similar note, avoid naming files -v or -r.... those are real
>pains. A friend of mine had to write system code to delete them... If
>he still has it sitting around, I'll pass it on.
In the light of the other easier solutions to this problem, *boggle* :)
You can use the Perl unlink() function, though, if you're really
desperate, but you don't need to.
On a side note, the following, as root, is quite a useful trick:
[root@riva ~]# cd /
[root@riva /]# touch -- --version
[root@riva /]# rm -rf *
rm (GNU fileutils) 4.0o
Written by Paul Rubin, David MacKenzie, Richard Stallman, and Jim Meyering.
Copyright (C) 1999 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
[root@riva /]# ls
--version dev info lost+found mnt root usr vmlinuz.old
bin etc initrd mirrors net sbin var world
boot home lib misc proc tmp vmlinuz
[root@riva /]#
(Not that I recommend actually trying the last command, but just touch
the file called --version. :) If you must test it then do it in a
scratch directory.)
The idea of this is that 'rm -rf *' expands to 'rm -rf --version boot
bin ...', and the --version there causes all the other arguments to be
ignored and just version information to be displayed.
Don't assume that you're invulnerable with this, though - 'rm -rf /'
would still trash your filesystem, so still be careful as root. It's a
useful safety net in case your brain-to-fingers connection slips a bit,
though.
--
Colin Watson [cjw44@cam.ac.uk]
Reply to: