Puneet Varma (Editor)

Chattr

Updated on
Edit
Like
Comment
Share on FacebookTweet on TwitterShare on LinkedInShare on Reddit

chattr is the command in the Linux operating system that allows a user to set certain attributes of a file residing on a Linux file system. lsattr is the command that displays the attributes of a file.

Contents

Modern BSD-like systems, including OS X, have analogous chflags to set, but no command specifically meant to display them; specific options to the ls command are used instead.

The Solaris system has no commands specifically meant to manipulate them. chmod and ls are used instead.

Other Unices, in general, have no analogous commands. The similar-sounding commands chatr (from HP-UX) and lsattr (from AIX) exist but have unrelated functions.

Among other things, the chattr command is useful to make files immutable so that password files and certain system files cannot be erased during software upgrades.

File system support

The attributes chattr and lsattr manipulate were originally specific to the Second Extended Filesystem family (ext2, ext3, ext4), and are available as part of the e2fsprogs package.

However, the functionality has since been extended, fully or partially, to many other systems, including XFS, ReiserFS, JFS and OCFS2. The btrfs file system includes the attribute functionality, including C which turns off the write-on-copy built in feature of btrfs due to slower performance associated with CoW.

Even the originally targeted file systems miss some features, as pointed further in this article.

chattr description

The form of the chattr command is:

  • -R recursively changes attributes of directories and their contents
  • -V is to be verbose and print the program version
  • -f suppresses most error messages
  • lsattr description

    The form of the lsattr command (gnu 1.41.3):

  • -R recursively lists attributes of directories and their contents
  • -V displays the program version
  • -a lists all files in directories, including dotfiles
  • -d lists directories like other files, rather than listing their contents
  • Attributes

    Some attributes include:

    Other attributes

    Other attributes include:

    File system support

    The chflags command is not specific to particular file systems. UFS on BSD systems, and HFS+, SMB, AFP, and FAT on OS X support least some flags.

    chflags description

    The form of the chflags command is:

    chflags [-R [-H | -L | -P]] flags file ...
  • -H If the -R option is specified, symbolic links on the command line are followed. (Symbolic links encountered in the tree traversal are not followed.)
  • -L If the -R option is specified, all symbolic links are followed.
  • -P If the -R option is specified, no symbolic links are followed. This is the default.
  • -R Change the file flags for the file hierarchies rooted in the files instead of just the files themselves.
  • Displaying

    BSD-like systems, in general, have no default user-level command specifically meant to display the flags of a file. The ls command will do with either the -lo, or the -lO, depending on the system, flags passed.

    Attributes

    All attributes can be set or cleared by the super-user; some can also be set or cleared by the owner of the file. Some attributes include:

    References

    Chattr Wikipedia


    Similar Topics