Filters
How to search
  • Plain words find names, texts and examples.
  • "two words" finds the exact phrase.
  • --name or -x finds an option.
  • #word looks only inside commands.
  • @grep finds lessons and labs that use grep.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Put ! before a word to leave it out. OR between words means one of them.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search

lsattr

List the file attributes (like i = immutable, a = append only).

Level
Everyday Linux
Group
Permissions
Needs root
For changes
Package
e2fsprogs

What it does

lsattr shows the extra attributes that chattr sets. Each letter in the first column is one attribute; - means not set. ls -l does not show them, so check lsattr when even root gets "Operation not permitted".

How to write it

lsattr [-RVadlpv] [FILE]...

Options 7

Most used

-R
List directories and their content recursively.
-a
Also list hidden files (names with a dot).
-d
List directories like files, not their content.
-l
Use long names for the attributes.
-p
Show the project number.
-v
Show the version/generation number.
-V
Show the version of the program.

Examples 10

$ run as a normal user# run as root (or with sudo)

  1. 1Attributes of one file

    lsattr /etc/resolv.conf
    ---------------------- /etc/resolv.conf

    No attributes set.

  2. 2Long names

    lsattr -l /var/log/app/audit.log
    /var/log/app/audit.log       Append_Only

    Easier to read.

  3. 3A directory itself

    lsattr -d /srv/archive

    Without -d you see the files inside.

  4. 4All files, also hidden ones

    lsattr -a ~

    Includes .bashrc and others.

  5. 5Search a tree for immutable files

    lsattr -R /etc 2>/dev/null | grep -- '-i-'

    Explains failing updates or config tools.

  6. 6Check SSH files for attacker tricks (security)

    lsattr /root/.ssh/authorized_keys /home/*/.ssh/authorized_keys

    i on authorized_keys can hide a backdoor key.

  7. 7Check before a package update

    lsattr /usr/bin/* 2>/dev/null | grep -v -- '^-*e*-* '

    Any attribute other than e (extents) is unusual in /usr/bin.

  8. 8Show the project number

    lsattr -p /srv/projects

    Used with project quotas on ext4/XFS.

  9. 9Compare with ls

    ls -l /etc/resolv.conf; lsattr /etc/resolv.conf

    ls shows the mode; lsattr shows the attributes.

  10. 10Errors on special files

    lsattr /dev/null
    lsattr: Operation not supported While reading flags on /dev/null

    Only normal files and folders have attributes.

Exit codes

0Done.
1Error.

Full manual

This page explains the command in simple words. The original manual has every detail.

In your terminal: man lsattr