rm-protection

by alanzchen

alanzchen / rm-protection

A safe alternative for "rm".

411 Stars 35 Forks Last release: over 3 years ago (v0.1.3) MIT License 22 Commits 5 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:

rm-protection logo

rm-protection

Codacy Badge PyPiversion Wheel python version Average time to resolve an issue PyPI Downloads

A safe alternative for

rm
with minimum difference

Ports: See #ports

Wiki: https://github.com/alanzchen/rm-protection/wiki

What is this?

rm-protection
is a safe alternative for removing files. It works exactly the same as
rm
(in fact it passes arguments to
rm
almost untouched). The only difference is that it refuses to proceed if a
.*.rm-protection
file is found and you failed to answer a question.

Why are you here?

I watched GitLab engineers trying to recover their production database live on YouTube.

Suddenly an idea struck me: What if

rm
prompted to ask "Which server are you on?" or "Which database are you trying to delete?"?

What if GitLab Ops had this...

The disaster could have been avoided.

Quick Start

  1. Install from PyPi and make an alias for

    rm-p
    .

    pip install rm-protection
    and optionally,
    alias rm="rm-p"
    for your daily user and root (so that it works for
    sudo
    ).
  2. Protect your files using

    protect
    . If you want to protect everything inside,
    protect -R
    .
  3. Happy rm-ing!

How does it work?

It consists of two utilities:

rm-p
and
protect
. The latter one is to help you protect files.

For example, you have a file called

important_file
and it is
protect
ed by
.important_file.rm-protection
.
rm-p
will recognize that
important_file
is protected and prompt to ask you a question stored in
.important_file.rm-protection
.
rm-p
will only proceed if you get the answer right.

See it in action:

Basic usage

It will also prevent you from deleting a directory with

protect
ed file(s) inside.

Recursive protection

Requirements

  • Python 2 or 3
  • Linux, unix and macOS
  • find

Comparison with alternative methods

| Methods | Can be used as "rm"? | Protect Specific Files | Flexibility | Additional Files | | ---------------------------------------- | -------------------- | ---------------------- | ----------- | ------------------ | | trash-cli | Yes | Somehow | High | Centralised Config | | rm -i | Yes | No or Somehow | High | | | safe-rm | Yes | Yes | Low | Centralized Config | | rm-protection | Yes | Yes | High | One for each |

Why don't you just use XXX?

rm-protection
aims at providing maximum protection and flexibility while making minimum impact on daily operation.

rm -i
can be very annoying,
trash-cli
is a bit complex (imagine you have a habit of emptying the trash without a second thought, or imagine you are trying to free up spaces on a budget vm).
Safe-rm
is inconvenient when you really need to delete something (you have to edit the configuration file).

Instead,

rm-protection
asks you a question set by you. You are fully covered when removing files (you won't accidentally empty the trash with
trash-cli
or
| yes
with
rm -i
), and you can quickly remove files (without editing any configuration files).

How to contribute?

Pull requests and issues are all welcome! Or tell others about this, so you can even

protect
the files you send to others!

Actually I don't care if people are using my implementation at all. I just think this kind of mechanism can be great -- using a

.rm-protection
file that asks questions.

If the community welcomes this mechanism, it will soon be ported/rewritten in every platform or languages, or even be implemented in the GNU coreutils. Then you can even get some default protections shipped with distributions and packages.

So if you agree on this mechanism, please share with others!

Ports

C

Current only offers binaries for Linux, source code available for building in macOS and unix.

(Note that it may behave slightly differently from

rm-protection
and it has not been tested by me.)

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.