Linux Comm Lsattr
# Linux lsattr Command
[ Linux Command Manual](#)
The Linux `lsattr` command is used to display the extended attributes of files.
Use (#) to change the attributes of a file or directory, and then use the `lsattr` command to query its attributes.
### Syntax
lsattr [file or directory...]
**Common Options**:
* -R: Recursively display the attributes of all files in a directory and its subdirectories
* -a: Display all files, including hidden files (files starting with .)
* -d: Display the attributes of the directory itself, not its contents
* -v: Display file version information
* -l: Display attribute names in long format
After running `lsattr`, the output format is typically as follows:
----i--------- /etc/passwd
* **Each column represents an attribute** (similar to the permission bits in `ls -l`).
* **`-` indicates the attribute is not set**, **letters indicate it is set** (e.g., `i`, `a`).
* **Common Attributes** (corresponding to `chattr`):
* `s`: secure deletion
* `u`: undeletable
* `c`: compressed
* `S`: synchronous updates
* `i`: immutable
* `a`: append only
* `d`: no dump
* `A`: no atime updates
* `I`: indexed directory
* `j`: data journalling
* `t`: no tail-merging
* `T`: top of directory hierarchy
* `e`: extent format
### Examples
**1. View the attributes of a single file**
lsattr /etc/passwd
Output example:
----i--------- /etc/passwd
The `i` indicates that the file is immutable (cannot be modified or deleted).
**2. View a directory and its contents**
lsattr -R /var/log/ # Recursively view all files under /var/log/
**3. View only the attributes of the directory itself (not its sub-files)**
lsattr -d /tmp/
**4. Display the attributes of hidden files**
lsattr -a ~/.bashrc
**5. Use in conjunction with chattr**
sudo chattr +i important_file.txt # Set to immutable lsattr important_file.txt # Check if it took effect
Output:
----i--------- important_file.txt
[ Linux Command Manual](#)
YouTip