Chattr prevents changes to both, files and directories.
chattr +i <file>
It makes even root unable to make changes to the file and unable to delete It.
chattr +i <dir>
It make even root unable to change the content of the directory and unable to delete It.
chattr -R +i <dir>
It does the same as the previous one, but It applies to sub directories as well.
To make a file editable again, and a directory changeable :
sudo chattr -i <file that cannot be modified>
Example :
In my case I did some changes to the file and executed this command :
chattr +i /etc/resolv.conf