Easy Tutorial
❮ Linux Comm Usermod Linux Comm Swatch ❯

Linux chattr Command

Linux Command Manual

The Linux chattr command is used to change file attributes.

This command can change the attributes of files or directories on an ext2 file system, which include the following 8 modes:

Syntax

chattr [-RV][-v&lt;version number>][+/-/=<attribute>][file or directory...]

Parameters

-R Recursively handle all files and subdirectories within the specified directory.

-v<version number> Set the version number of the file or directory.

-V Display the execution process of the command.

+<attribute> Enable the specified attribute for the file or directory.

-<attribute> Disable the specified attribute for the file or directory.

=<attribute> Specify the attribute for the file or directory.

Example

Use the chattr command to prevent a critical file from being modified:

chattr +i /etc/resolv.conf
lsattr /etc/resolv.conf

This will display the following attributes:

----i-------- /etc/resolv.conf

Allow a file to only have data appended to it, but not deleted, suitable for various log files:

chattr +a /var/log/messages

Linux Command Manual

❮ Linux Comm Usermod Linux Comm Swatch ❯