We sometimes need to protect some files or folders from being deleted by accident by you or users sharing your computer. Protecting your files or folders will also help you disallow unauthorized users to delete your sensitive contents.

To do this, we may use system encryption software, but changing just file/folder user access permissions will be enough to protect them. For example, chattr is a command line utility that allows via the terminal to change file or folder permissions.

  • Protecting Files

Open the terminal and run this command to protect any file of your choice from being deleted:

sudo chattr +i filename

Replace filename with your own. To remove this protection, run this command:

sudo chattr -i filename

  • Protecting Folders

To protect a folder from being deleted, use this command:

sudo chattr -R +i foldername

To unprotect the folder, use this command:

sudo chattr -R -i foldername

That's it!

Post a Comment