Only the superuser can execute chatttr (change attribute) to modify the 16 different attributes of Linux files. Typically, valid attribute definitions range from 8 to 14 types, with support for attributes varying across different Linux distributions and file systems. Some attributes might only be applicable to specific file systems.
The usage of chattr is somewhat similar to chmod. The "+" symbol is used to add attributes, "-" to remove attributes, and "=" to directly set attributes.
Examples:
$ chattr +i test.txt ←dds the "i"(immutable) attribute to the file "test.txt. chattr -V +i test.txt chattr 1.42.9 (28-Dec-2013) Flags of file set as ----i--------e-- ←← The "i" attribute has been added |
In the above example, the "-i" (immutable) option is an extreme case because making a file immutable can have serious consequences. Once a file is set as immutable, even the superuser/root cannot modify, delete, or alter it.
The chattr command is very useful for enhancing file security and control, especially when dealing with critical system files or when you want to prevent accidental modifications.
Valid attribute definitions include [aAcdDisSu], representing specific meanings. For more detailed explanations and the precise usage of the chattr command, please refer to the provided link.