Thứ Sáu, 5 tháng 9, 2014

Set File Attributes In Linux Using Chattr Command

 Set File Attributes In Linux Using Chattr Command

Chattr is a command used to set / unset file attributes in Linux.
Using chattr it is possible to make a file immutable. That is, even a root user will be prohibited from deleting the file.
To prevent anyone - even a root user - from deleting a file, you set the immutable bit of the file using the chattr command as follows -

# chattr +i filename

The immutable bit option +i can only be set by the root user. So either you should have root priviledges or you need to use sudo to execute the command.
Once the +i bit is set, even root user won't be able to delete or tamper with the file.

To unset the immutable flag -

# chattr -i filename

chattr can be used to set/unset many more file attributes.

For example, if you want to allow everybody to just append data to a file and not change already entered data, you can set the append bit as follows:

# chattr +a filename


Now the filename can only be opened in append mode for writing data. You can unset the append attribute as follows:

# chattr -a filename


To know more about chattr command, check its man page. 

Share This!


Không có nhận xét nào:

Đăng nhận xét