immune your files and folders from accidental deletion.

December 18th, 2006 mysurface Posted in Admin, chattr, man, Misc, sudo | Hits: 31465 | 2 Comments »

Okay, when you accidentally type

rm LoveLetterFromJane.txt

Your file are gone, can’t resume it at trash, there are no trash, the document are important to you! Oh My God!! you smack your box!

In Linux, you can change attribute for your files and folders, to make it immune from accidental deletion, not even with root permission. To do this art, you need two things.

1. chattr
2. root access or sudo.

Let say I have a folder call “darling”

sudo chattr +i darling

By enable “immunity” (+i) to “darling”, the entire folder can’t be delete by just using rm even you are root. The files and sub folders inside “darling” can’t be delete as well. You cannot create files or sub folders in “darling” too.

If you want to change back to normal, take away her “immunity” (-i).

sudo chattr -i darling

Besides adding “immunity”, chattr can do more, read the full manual to know more.

man chattr

2 Responses to “immune your files and folders from accidental deletion.”

  1. Great, except it doesn’t work. Might be because Im using reiserfs though.

  2. Ops…. Sorry I should have mention it is for ext2 or ext3 file system.

Leave a Reply