
lsattr Command in Linux
lsattr is a command used in Linux to display the attributes of files and directories. Attributes are special properties that provide extra control over how files can be modified. For example, an attribute might prevent a file from being accidentally deleted or modified.
By using lsattr, you can see which attributes are set for each file, giving you more insight into how the system handles them. This is particularly useful for administrators and advanced users who need to ensure the integrity and security of important files.
Table of Contents
Here is a comprehensive guide to the options available with the lsattr command −
Syntax of lsattr Command
The general syntax to use the lsattr command on Linux is as follows −
lsattr [options] [file...]
In this command −
- [options] are various flags you can use to customize the command's behavior.
- [file...] specifies the files or directories whose attributes you want to display. If omitted, lsattr will default to the current directory.
lsattr Command Options
For customizing the view of directory contents, the Linux ls command on Linux offers many options. Here's a table that highlights the main features −
Options | Description |
---|---|
-a | Shows all files, including hidden ones. |
-d | Displays attributes of directories themselves, rather than their contents. |
-R | Recursively lists attributes for all files in subdirectories. |
-v | Shows the version of the attributes. |
-V | Displays the program version. |
-p | Displays the properties of each file in the directory without listing the directory itself. |
-L | Follows symbolic links and lists the attributes of the target file. |
Examples of lsattr Command in Linux
These are some practical applications of the command lsattr in Linux.
- Displaying Attributes of All Files
- Displaying Attributes of a Specific File
- Showing Attributes of Hidden Files
- Displaying Directory Attributes
- Recursively Listing Attributes
Displaying Attributes of All Files
If you want to see the attributes of all files in the current directory, you can use the command lsattr. This provides a quick overview of the attribute settings for all files.
lsattr
This command shows the attributes of all files in the current directory, and gives you a quick snapshot of the attribute settings.

Displaying Attributes of a Specific File
To check the attributes of a specific file, you can simply use lsattr with the name of the text document, such as document.txt. This helps you understand the controls in place for that file.
lsattr document.txt
This command lists the attributes of document.txt, and allows you to see the specific attributes set for this file.

Showing Attributes of Hidden Files
Hidden files, which start with a dot (.), are often used for system configurations. To include them in your attribute listing, use the -a option.
lsattr -a
This command displays the attributes of all files, and includes hidden ones in the current directory, ensuring that you see all relevant files.

Displaying Directory Attributes
If you want to check the attributes of directories themselves rather than their contents, the -d option is useful.
lsattr -d directory_name
This command lists the attributes of the specified directory, and focuses on the directory itself instead of the files within it.

Recursively Listing Attributes
To view the attributes of all files in the current directory and its subdirectories, you can use the -R option. This helps in getting a comprehensive view.
lsattr -R
This command provides a complete view of the file attributes throughout the directory tree, including nested folders.

Showing Version of Attributes
If you need to see the version of the attributes for files, the -v option can be used.
lsattr -v
This command lists the version number of attributes for the files, which can be important for tracking changes and updates.

Conclusion
The lsattr is a crucial command for Linux users who need to manage and view file attributes. Whether you're ensuring files are protected from accidental changes or checking hidden attributes, lsattr provides the necessary functionality to control file properties effectively.
In this tutorial, we covered the syntax, options, and practical examples of using the lsattr command. Mastering this command will enhance your ability to manage file attributes and improve the security and integrity of your file system in a Linux environment.