The chattr
command in Linux is used to change file attributes on a filesystem. It allows users to set or remove certain attributes that can affect how files are accessed or modified, providing an additional layer of security and control over file management.
The basic syntax of the chattr
command is as follows:
chattr [options] [arguments]
+a
: Append-only. Files can only be opened in append mode for writing.+i
: Immutable. The file cannot be modified, deleted, or renamed.-a
: Remove append-only attribute.-i
: Remove immutable attribute.+e
: Allow the file to be used for extents (for filesystems that support it).-e
: Remove extent support.chattr +i myfile.txt
This command makes myfile.txt
immutable, preventing any changes to it.
chattr -i myfile.txt
This command allows modifications to myfile.txt
again.
chattr +a mylogfile.log
This command allows mylogfile.log
to be opened only in append mode.
lsattr myfile.txt
This command displays the current attributes of myfile.txt
.
chattr +i +a myfile.txt
This command makes myfile.txt
both immutable and append-only.
lsattr
to check the current attributes of files before making changes.