Home
Welcome to the rm-protection wiki!
rm-protection
is available on PyPi.
sudo pip install rm-protection
and optioanlly,
alias rm="rm-p"
git clone https://github.com/alanzchen/rm-protection.git
sudo pip install ./rm-protection
and optionally,
alias rm="rm-p"
rm-protection
provides two utilities: rm-p
and protect
.
Before you can feel safer when using rm
, you will need to protect
your files and directories.
protect file1 file2 directory1 directory2
For example, if you want to protect your database directory db
, you should run protect db
. It will prompt to ask you for a question and an answer.
From then on, when you try to rm-p
this directory, you will be asked to enter the right answer to proceed.
From version 0.1.2 on, protect
can protect directories "recursively" by adding -R
. When you delete /home/user/Documents/file
, if Documents
is protected "recursively", rm-p
will prompt to ask. However, if Documents
protected but not "recursively" protected, rm-p
will only display an warning message without prompting.
For example,
protect file1 file2 -R -- -file -directory
Arguments start with -
will be escaped after --
.
Under the hood, protect -R
adds a mark R
at the third line of the protection file. It does not actually recursively create a protection file for each single file inside the directory. Instead, rm-p
will check if any of the parent directories is protected when evaluating an argument.
rm-p
is designed to work exactly the same as rm
. In fact, it passes your arguments to rm
unless a protection file is protected.
rm-p -rf file1 file2 file3 dir1 dir2
rm-p -rfi -- --file
To prevent yourself from removing protected file in daily operation, make sure you have alias set in .profile
or .bashrc
or equivalents.
rm-p
does not try to catch errors in advance. For example, rm-p ..
will still be passed to rm
, which will then raise an error.
You may need to disable the protection for a file or directory.
rm-p
will warn you if the file ends with .rm-protection
. Assuming that you know explicitly you are removing the protection, rm-p
will not ask the question you set in the protection file, instead, it asks for a "yes" or "no".
This allows you to bulk remove protection files. For example, yes | rm-p .*.rm-protection
.