Top Qs
Timeline
Chat
Perspective

Chattr

Command in Linux From Wikipedia, the free encyclopedia

Remove ads

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

Quick Facts Original author(s), Operating system ...
Remove ads
Quick Facts Operating system, Platform ...

Most BSD-like systems, including macOS, have always had an analogous chflags command to set the attributes, but no command specifically meant to display them; specific options to the ls command are used instead. The chflags command first appeared in 4.4BSD.

Solaris has no commands specifically meant to manipulate them. chmod[1] and ls[2] are used instead.

Other Unix-like operating systems, 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.[3]

Remove ads

In Linux systems (chattr and lsattr)

Summarize
Perspective

File system support

The command line tools chattr (to manipulate attributes) and lsattr (to list attributes) 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 the C flag, which turns off the built-in copy-on-write (CoW) feature of btrfs due to slower performance associated with CoW.

chattr description

The form of the chattr command is:

 chattr [-RVf] [-+=AacDdijsTtSu] [-v version] files...
  • -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):

 lsattr [ -RVadv ] [ files...  ]
  • -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:

More information Attribute, lsattr flag ...

Notes

  1. Only the superuser or a process possessing the CAP_LINUX_IMMUTABLE capability can set or clear these attributes.
  2. These attributes are not honored by the ext2 and ext3 filesystems as implemented in the current mainline Linux kernels.
  3. These attributes only make sense for Copy-on-Write file-systems such as btrfs.
  4. Only the superuser or a process possessing the CAP_SYS_RESOURCE capability can set or clear this attribute.
  5. This attribute is not honored by the ext4 filesystem as implemented in the current mainline Linux kernels as reported in Bug #17872.
Remove ads

In BSD-like systems (chflags)

Summarize
Perspective

File system support

The chflags command is not specific to particular file systems. UFS on BSD systems, and APFS, HFS+, SMB, AFP, and FAT on macOS support at 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 traditional 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:

More information Attribute, ls flag ...
Remove ads

See also

  • ATTRIB – analogous command in MS-DOS, OS/2 and Microsoft Windows
  • chown – change file/directory ownership in a Unix system
  • chmod – change file access control attributes in a Unix system
  • cacls – change file access control lists in Microsoft Windows NT

Notes

Loading content...

References

Loading content...
Loading related searches...

Wikiwand - on

Seamless Wikipedia browsing. On steroids.

Remove ads