Overview
lsattr is used to check special attributes applied to files at the file system level, such as immutable or append-only. These attributes control file modifications and deletions independently of standard file permissions.
Key Features
- Checks special file system attributes
- Specific to ext2/3/4 file systems
- Displays attributes set by chattr
Key Options
The lsattr command is used to check special file attributes and offers several useful options.
Display/Format
Generated command:
Try combining the commands.
Description:
`lsattr` Executes the command.
Combine the above options to virtually execute commands with AI.
Usage Examples
Various ways to check special attributes of files and directories using the lsattr command.
View Attributes of Files in Current Directory
lsattr .
Displays the attributes of all files and directories in the current directory.
View Attributes of a Specific File
lsattr my_important_file.txt
Checks the special attributes of a specified file.
View Attributes of a Directory Itself
lsattr -d my_directory/
Checks the attributes set on the directory itself, not its contents.
View Attributes Recursively for Subdirectories
lsattr -R my_project_folder/
Recursively displays the attributes of a specified directory and all files and directories within it.
View Attributes Including Hidden Files
lsattr -a .
Displays the attributes of all files in the current directory, including hidden files.
Tips & Notes
Useful tips and points to consider when using the lsattr command.
Relationship with chattr Command
The attributes checked by lsattr are set using the chattr command. For example, `chattr +i file.txt` makes the file immutable, preventing modification or deletion, which can be verified with `lsattr file.txt`.
Key Attribute Characters
Some important attribute characters you might see in lsattr output.
- i (immutable): The file cannot be modified or deleted. Even the root user has difficulty changing it.
- a (append-only): Only data can be appended to the file; existing data cannot be modified or deleted.
- S (synchronous): Changes to the file are written to disk immediately.
- j (data journaling): File data is journaled (default behavior in ext3/4).
File System Limitations
The lsattr and chattr commands only work on Linux extended file systems like ext2, ext3, and ext4. They do not function on other file systems such as XFS, Btrfs, or NTFS, or require different tools.