Linux Tips and Tricks

Linux Tips and Tricks

Create a File and make it as unalterable

October26

The command chattr is used to change the file as unalterable.

It cannot be changed or deleted by even root

example:

$ touch testing_file

creating a empty file using touch command

$ ls -lrt testing_file
-rw-r–r– 1 kamaraj kamaraj 0 2010-10-26 20:02 testing_file

checking the availabiltiy of the file

$ chattr +i testing_file
chattr: Operation not permitted while setting flags on testing_file

The command chattr is not allowing me to change the settings. so i am gonna try as root

$ sudo chattr +i testing_file
[sudo] password for kamaraj:
$

Yes, i applied the settings.
i – immuatable. (refer the manual page : man chattr)

$ echo “test” > testing_file
bash: testing_file: Permission denied

Trying to add a word “test” in the testing_file. But it is not allowing me to add the text. Let me try as root

$ sudo echo “test” > testing_file
bash: testing_file: Permission denied

Even in the root also it is not allowing me to add the text “test”. Ok, then remove the immuatable settings

$ sudo chattr -i testing_file

removed the immuatable settings. ( you have to remove as root )

$ echo “test” > testing_file

$ cat testing_file
test

Note : This work only on ext2/ext3 filesystems.

posted under Uncategorized

Email will not be published

Website example

Your Comment:


Recent Comments

    Categories