Skip to content

lsattr Linux Command Guide

The Linux lsattr command is used to view and modify file attributes on ext2/ext3/ext4 file systems. It displays the attributes of files and directories, such as whether a file can be modified, deleted, or whether the file is immutable. By using lsattr, you can control the behavior of files and directories to enhance security and prevent accidental changes.

lsattr Syntax:

Terminal window
lsattr [option] [parameter]

Options:

OptionDescription
-aList all files in specified directories
-dList directories like other files
-ECancel the effect of any previous -R
-RRecursively list attributes in directories
-VOutput version information and exit

Parameters:

ParameterDescription
filenameFile or directory name to show attributes for
directoryList attributes for the directory and its contents

lsattr Command Samples:

List Permissions of a File

Terminal window
lsattr file.txt

Display the attributes of a specific file named “file.txt”.

View All Attributes of a Directory

Terminal window
lsattr -d directory

Show all attributes of a directory named “directory”.

Show Only Inode Status

Terminal window
lsattr -i file.txt

Display only the inode status of a file named “file.txt”.

Recursively List File and Directory Attributes

Terminal window
lsattr -R /path/to/directory

List recursively all attributes of files and directories within the specified directory.

Display Attributes with Long Listing Format

Terminal window
lsattr -l file.txt

Show the attributes of a file with a long listing format.

Modify Immutable Attribute of a File

Terminal window
lsattr -i +i file.txt

Set the immutable attribute for a file named “file.txt”.

Remove Immutable Attribute from a File

Terminal window
lsattr -i -i file.txt

Remove the immutable attribute from a file named “file.txt”.

lsattr FAQ:

{Questions}

How do I use lsattr in Linux?

To use the lsattr command in Linux, execute the following command:

Terminal window
lsattr --A /path/to/directory

What does the lsattr command display in Linux?

The lsattr command displays the attributes of files or directories in Linux.

How can I view all attributes of a file using lsattr?

To view all attributes of a file in Linux, you can use the following command syntax:

Terminal window
lsattr -d /path/to/file

How do I remove a specific attribute from a file with lsattr?

To remove a specific attribute from a file using lsattr in Linux, you can use the following command structure:

Terminal window
chattr -<attribute> /path/to/file

Can lsattr display only a specific type of attribute?

Yes, lsattr in Linux can be used to display only a specific type of attribute using the following command format:

Terminal window
lsattr -a /path/to/directory

How do I recursively list attributes of files and directories with lsattr?

To recursively list attributes of files and directories in Linux using lsattr, you can execute the command as follows:

Terminal window
lsattr -R /path/to/directory

Applications of the lsattr command

  • Viewing the attributes of files and directories on a Linux system
  • Checking if a file or directory has immutable, append-only, or other special attributes set
  • Determining if a file or directory is protected against certain operations
  • Managing advanced file and directory permissions and protections on a Linux system