Linux Attributes Command
The lsattr and chattr commands in Linux are used to view and modify file attributes on a filesystem. These attributes provide additional control over how files are handled by the system.
lsattr Command
The lsattr command is used to list the attributes of files and directories.
Syntax:
lsattr [options] [file...]
Options:
-a: List all files, including hidden files.-d: List directories themselves, not their contents.-R: Recursively list attributes of files in subdirectories.
Example:
To list attributes of a file:
lsattr myfile.txt
chattr Command
The chattr command is used to change the attributes of files and directories.
Syntax:
chattr [options] [attributes] [file...]
Options:
-R: Recursively change attributes of files in subdirectories.-V: Display verbose output.
Attributes:
+a: Allow only append operations to the file.+i: Make the file immutable (cannot be modified, deleted, or renamed).-a: Remove the append-only attribute.-i: Remove the immutable attribute.
Example:
To make a file immutable:
chattr +i myfile.txt
Practical Example
To recursively list attributes of all files in a directory:
lsattr -R /path/to/directory
To remove the immutable attribute from a file:
chattr -i myfile.txt