Entry
How do I protect my files from getting deleted by a "rm *" or "rm *.*" ?
Nov 12th, 2001 22:35
Christiano Medeiros, Jay Nayegandhi, Kevin Gipe, Rakhal Barve,
To protect my files from "rm *", intentionally or un-intentioannly, I
would do the following:
(1) I think of an alphabet, which is not one of the swithes of the "rm"
command for the flavour of UNIX I am using (e.g. "q"). I can find this
with the help of "man rm".
(2) I create two files, whose names are "-alphabet" and "-
alphabet.alphabet" (i.e. "-q" in my case), where "aplphabet" is any of
the above mentioned alphabets. These files must be created in those
directories, whose contents I want to protect.
I use the following command in all such directories for this:
$ > -q
$ > -q.q
(3) Once this is done, the "rm *" and "rm *.*" commands would fail to
execute, and none of my files in that directory would be deleted.
(4) If I want to delete the "-q" and "-q.q" files, I run the following
commands:
$ rm ./-q
$ rm ./-q.q
Another option that I use it to add a file with name "-i". Similar
effect, but instead of disabling rm * all together, it prompts you for
confimation as in the rm -i command.This works great if you want to be
careful with rm * on a particular directory.
If you want to enforce this behavior on a whole machine, simply add an
alias line in your .profile file.
alias rm="rm -i"
Though this will prompt for verification on every single rm statement
you execute (which may be annoying)...
If you are sure you want to delete something, you can always have
another alias that will not ask you to verify doing the "rm". Your
commands can be:
alias rm='/bin/rm -i'
alias rmf='/bin/rm -f'
Stick the above two lines in your .profile. Incidentally, this is not
a "system-wide" setting. It works only for the individual and only for
that session.