LinuxCommandLibrary

lsattr

List file attributes on a Linux second-extended filesystem

TLDR

Display the attributes of the files in the current directory

$ lsattr
copy

List the attributes of files in a particular path
$ lsattr [path]
copy

List file attributes recursively in the current and subsequent directories
$ lsattr -R
copy

Show attributes of all the files in the current directory, including hidden ones
$ lsattr -a
copy

Display attributes of directories in the current directory
$ lsattr -d
copy

SYNOPSIS

lsattr [-RadlvV] [filename...]

PARAMETERS

-R
    Recursively list attributes of directories and their contents.

-a
    List all files in directories, including those whose names start with '.'.
Useful with -d option.

-d
    List directories like other files, rather than listing their contents.

-l
    Long listing format. Shows the attribute flags as text characters.

-v
    Print the program version.

-V
    Prints verbose output during execution.

[filename...]
    The file(s) or directory(ies) to list the attributes of.

DESCRIPTION

The lsattr command displays the file attributes set on files and directories within a Linux second extended file system family (ext2, ext3, ext4). These attributes are used to control the behavior of the file system with respect to these files, such as whether they can be modified or deleted, or if they should be compressed when written to disk. The output shows the attribute flags set for each file or directory. This command is useful for administrators and developers who need to manage the extended attributes of files, often used for security or performance reasons.

Note that these attributes are filesystem specific and are not the same as standard file permissions. Extended attributes are a crucial part of the Linux filesystem and understanding them is key to advanced system administration and file system debugging.

CAVEATS

The lsattr command only works on file systems which support extended attributes (ext2, ext3, ext4, etc.). It won't work on other file systems like FAT32 or NTFS. Some attributes may only be effective if kernel support for that specific functionality is present.

ATTRIBUTE FLAGS

The output of lsattr displays one or more attribute flags for each file. Common flags include: i (immutable), a (append-only), c (compressed), d (no dump), e (extent format), j (journaled data), s (secure deletion), t (no tail-merging), u (undeletable). Consult the chattr(1) manual page for a complete and up to date listing.

USAGE EXAMPLES

lsattr myfile.txt: Displays the attributes of the file 'myfile.txt'.
lsattr -R mydir: Recursively displays the attributes of all files and directories within 'mydir'.
lsattr -a .: Shows hidden files attributes in current directory.
lsattr -d .: Shows only directory attributes. This is similar to "stat -c '%A %n' ."

HISTORY

The lsattr command is a core part of the e2fsprogs package, which provides essential file system utilities for ext2/ext3/ext4 file systems. It was developed alongside the extended attribute functionality in Linux.

SEE ALSO

chattr(1), stat(1), chmod(1)

Copied to clipboard