-
a quick (rm) trick: *nix
While playing around on the school's unix sys I found a neat trick
just from playing around with the cat command.
It is feared that a unix newbie will try a 'rm *' or a 'rm -rf *' command.
that will deleted his whole file sys for his account.
So I did a 'cat>-z'
'C^+d'
then catted -z file it was empty as I like it to be.
then try a rm * it gave me a invalid option mesg
then try a rm -rf * the same mesg happen again.
it would let me excute the rm * command. For as I know I guess the
-z file is passed or seen as part of the rm command.
(note:try in a create directorywith garbage files in this dir)
it will not remove none of the files with a rm * U have to use the file name.
If anyone can tell me more about how this works I would greatly love the info.
thx,P7
-
I guess it's because when you use * , it adds the -z to the command line
rm -rf -z , and since it's not a valid option, it produces the error message. Since -z would be the first file to be picked, it seems to be a nice protection against mass deletion.. :) . All I have to say.. hope that's the explanation. If there are some more esoteric issues involved, I dunno.
-
Yes, that's exactly what's happening. Any file whose name begins with a "-" will be seen as a command line option instead of a file. I discovered this a while back when I got my new HP digital camera working under Linux and realized it liked to name images -001, -002, -003, etc... ;)