lsattr Command
The lsattr command lists file attributes on ext2, ext3, and ext4 filesystems. It displays special file properties that control how the filesystem handles files, such as immutable, append-only, and compression attributes.
Syntax
Description
The lsattr command displays file attributes that are specific to ext2, ext3, and ext4 filesystems. These attributes provide additional control over file behavior beyond standard Unix permissions.
Key features:
- Display extended file attributes
- Work with ext2/ext3/ext4 filesystems
- Show special file properties
- Support recursive directory traversal
- Complement the chattr command
Common Options
| Option | Description |
|---|---|
-a |
List all files including hidden files (starting with .) |
-d |
List directories like other files, not their contents |
-R |
Recursively list attributes of directories and contents |
-v |
List the file's version/generation number |
-l |
Print the options using long names instead of single characters |
-p |
List the file's project number |
File Attributes
| Attribute | Symbol | Description |
|---|---|---|
| Append only | a |
File can only be opened for appending |
| Compressed | c |
File is compressed by the kernel |
| No dump | d |
File is not a candidate for backup when dump is run |
| Extent format | e |
File uses extents for mapping blocks |
| Immutable | i |
File cannot be modified, deleted, or renamed |
| Data journaling | j |
File data is written to journal before being written to file |
| Secure deletion | s |
File blocks are zeroed when deleted |
| No tail-merging | t |
File tail should not be merged |
| Undeletable | u |
File contents are saved when deleted |
| No atime updates | A |
File access time is not updated |
| Synchronous updates | S |
File changes are written synchronously |
| Top of directory hierarchy | T |
Directory is top of directory hierarchy |
Examples
List attributes of a file
Shows attributes of the specified file
List attributes of all files
Shows attributes of all files in current directory
List attributes including hidden files
Shows attributes of all files including hidden ones
List directory attributes
Shows attributes of the directory itself, not its contents
Recursive listing
Recursively shows attributes of all files and subdirectories
Show version numbers
Displays file version/generation number along with attributes
Long format output
Shows attributes using long names instead of single characters
Show project numbers
Displays project number (if supported by filesystem)
Understanding lsattr Output
Output Format
Different output formats showing attributes
Common Attribute Combinations
Examples of different attribute combinations
Working with chattr
Setting Attributes
Make file immutable
Set and verify immutable attribute
Make file append-only
Set and verify append-only attribute
Remove attributes
Remove attributes and verify changes
Practical Use Cases
System Protection
Protect system files
Protect critical system files from modification
Log file management
Ensure log files can only be appended to
Performance Optimization
Disable atime updates
Improve performance by disabling atime updates
Backup Management
Exclude files from backup
Mark temporary files to exclude from backups
Troubleshooting
Common Issues
Filesystem not supported
Handle unsupported filesystem errors
Permission denied
Handle permission issues
Cannot modify immutable files
Troubleshoot immutable file issues
Best Practices
File Attribute Best Practices
- Document Changes - Keep records of which files have special attributes
- Use Sparingly - Only set attributes when necessary
- Test First - Test attribute effects on non-critical files
- Backup Strategy - Consider how attributes affect backups
- Security Awareness - Understand security implications of each attribute
- Regular Audits - Periodically review files with special attributes