About Me

header ads

Ubuntu: how to make a file or folder indelible and immutable

I do not know how many times have you ever accidentally delete a file or entire directories: A tragedy, right? If you do this manually, then you'll still find the trash files and folders ready to be restored, but if you are wrong to give a parameter to the command from the terminal rm (Which is there to remove file/directory), then the recovery is much more complicated. In order to prevent some of our important files or directories from being accidentally removed, changed or deleted, we can rely on chattr (change attribute), which has a parameter that is exactly our case, to prevent unpleasant incidents.


Making immutable/indelible a file

Open the terminal and type:
sudo chattr +i file_name
and the file "file_name" will become immutable. If instead you want to restore it, type:
sudo chattr -i file_name
Making immutable/indelible a folder

Open the terminal and type:
sudo chattr -R +i folder_name
and the folder "folder_name" become immutable. If instead you want to restore it, type:
sudo chattr -R -i path_of_the_directory
All very simple and useful, do not you think?

Post a Comment

0 Comments