How to avoid accidental deletion of files in Linux
This post explains how to avoid accidental deletion of files (install rm-protection) in Linux. Although Gnu / Linux is a very safe operating system, the fact is that sometimes we delete files by mistake and then it is difficult to recover. The chances happening this is more if your computer is shared.
Here I am explaining how to avoid this issue by using a tool called rm-protection. It’s a python program that will help us to avoid these problems and hence we can avoid the external recovery programs. The operation of rm-protection is very simple as it prevents the deletion by mistake of any file in Gnu / Linux.
To install rm-protection, first we have to install pip, a package management system used to install and manage software packages written in Python. Please check the following commands to install pip on different Linux distributions:
Arch Linux and derivatives
sudo pacman -S python-pip
RedHat / OpenSUSE
sudo yum install epel-release sudo yum install python-pip
Ubuntu / Debian / derivatives
sudo apt update sudo apt-get install python-pip
Install rm-protection:
Once pip installed, we can proceed with the installation of rm-protection. Run the following command to install rm-protection.
sudo pip install rm-protection
The rm-protection consists of two utilities: rm-p and protect. Once the program is installed, we have to select the files or directories that we want to encrypt. You can protect your files using protect. If you want to protect everything inside, use protect -R.
protect grepitout.txt protect -R /home/grepit/
Once hit enter, the program will ask us for a security question and an answer. After completing this, every time we try to delete some protected file using rm-p, the operating system will ask us the question that we have marked before and we have to provide the answer to delete it. Otherwise, it will give an error and we will not be able to delete the file.
rm-p grepitout.txt
See this actions in the featured image of this post.
We can set alias rm=”rm-p” to avoid the usage of rm command. Also, please check the github repository of the program.
That’s it!
Read More:
- How to Install Chromecast on Ubuntu Linux
- 7 Best Evernote Clients and Alternatives for Ubuntu
- How to logout from shell without saving bash history
- How to remove a file using inode number
- How to delete files older than N Days in Linux
If you like this post and wish to receive more articles from us, please like our FB page: Button
Your suggestions and feedbacks will encourage us and help to improve further, please feel free to write your comments.
For more details on our services, please drop us an E-mail at info@grepitout.com
Nice post. Very helpful…Thanks.