How to protect accidental file deletion in Linux

Linux folders and files

Although Gnu / Linux is a very secure operating system, the truth is that sometimes it happens that we delete files by mistake and then it's hard to get back. This can happen and more if our computer is shared.

Next we will tell you how to avoid this thanks to a program called rm-protection, a python program that will help us avoid these problems and avoid problems with external recovery programs. The operation of rm-protection is very simple as it avoids the accidental deletion of any file in Gnu / Linux.

First we have to install the RM-Protection program and in some cases we have to install special python plugins, for this we open a terminal and write the following:

Arch Linux and derivatives

sudo pacman -S python-pip

RedHat / OpenSUSE

sudo yum install epel-release
sudo yum install python-pip

Debian / Ubuntu / derivatives

sudo apt-get install python-pip

Installation of the rm- protection program:

sudo pip install rm-protection

Once the program is installed, we have to select the files or directories that we want to encrypt, for this we only have to write the following:

protect archivo.txt
protect -R carpeta/

Once enter is pressed, the program will ask us a security question and an answer. After establishing this, every time we try to delete a protected file, the operating system will ask us the question that we have marked before and we also have to enter the answer that we have entered before, as we wrote it, otherwise it will give an error and we will not be able to delete the archive. And although it seems tedious, we can do something like encrypt the home folder and make sure our files are not accidentally deleted.

The system that uses rm-protection is simple and the program has a basic operation, something that we can verify thanks to the github repository of the program, but it is fully functional because the question will make us determine what we are doing and what file we are deleting.

The content of the article adheres to our principles of editorial ethics. To report an error click here!.

7 comments, leave yours

Leave a Comment

Your email address will not be published.



  1. Responsible for the data: AB Internet Networks 2008 SL
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   Fabian said

    «... difficult to recover ...?»; For that there are programs like Photorec, another thing is to put more security, which is something else.

  2.   Shupacabra said

    I never recovered a file with photorec, I seriously wonder if it is useful for anything

  3.   Yeray said

    My photorec saved me from recovering all my data in KaOS, the only problem that I found later is that the recovered files had a different nomenclature (f9017296.avi, to mention an example).

    A greeting.

  4.   ldjavier said

    I am new to the Linux world. For years I have yearned to learn about Linux but I stayed in my comfort zone with windows, until my disk failed and although I formatted it and tried to reinstall windows 7 (even w10) I could not do it and decided to install ubuntu 16. Before formatting my disk backed up most of my information but lost some photos. In Ubuntu I tried to recover them with photorec and it generated a lot of folders with various files, including photos, but now I can't delete the files that don't interest me. In windows it was simpler, maybe a right click, maybe change attributes or use a program but I don't know how to do it in linux. Can someone guide me please? Thanks

  5.   URxvt said

    I use the trash-cli program, which does is move the files to the trash instead of deleting them as if it were the rm command.

    The command is trash but I put an alias to it, faster to type. It is used like this:

    It is not a good idea to create the alias rm because then you will change your PC, you will use rm thinking that nothing happens and xD files will be deleted.


  6.   Oscar said

    What I do is move what I want to delete to / tmp and I only have to move it again if I am confused.

    The problem is that if you turn off the computer you lose the files.

    If you want to have a permanent trash can, you can create a directory and move the files you want to delete there and occasionally clean it (when you are sure that you don't need the files).

  7.   Joanna enriq said

    Make files immutable (immutable) so that no user, not even root, can edit or delete without first removing the 'immutable' attribute:

    $ chattr + i / path / filename

    The 'immutable' attribute is removed as follows:

    $ chattr -i / path / filename