How To Prevent Deleting Files Accidentally? – POFTUT

How To Prevent Deleting Files Accidentally?


Every system admin horror is deleting files accidentally especially important and not backup ed configuration files. Here is how can we recover deleted files from Linux systems which is next situation if we skipped this step.

Ask Before Deleting Files

rm is defacto tool to remove files from Linux system. We can set up a mechanism to ask before deleting files with a simple alias setup like below.

$ echo 'alias rm=rm -i' >> .bashrc

This will add new alias for rm command with <strong>-i  option.

Login and Use Less Privileged User /Do Not Use Root Always

Using root user makes system administrator more powerful and less problematic but as you guess power without control will create problems. Use a less powerful user with sudo capability which is default in Ubuntu.

Change Permissions and Owner User Group

Keep permissions strict so do not give 777 to files as far as it is not needed.

We can change permission like

$ chmod 640 config.cfg

Add Protected Attribute

Linux provides read-only attribute which can be given by root. This attribute will make the file read-only.

$ sudo chattr +i pnggrad8rgb.png

LEARN MORE  What is chmod 777?

1 thought on “How To Prevent Deleting Files Accidentally?”

Leave a Comment