Chattr

From Wikipedia, the free encyclopedia

chattr is a command in the Linux operating system that allows a user to set certain attributes on a file residing on many Linux filesystems. chflags is the analogous command on modern BSD systems, including OS X. The commands are similar to the attrib command on DOS, OS/2 and Microsoft Windows. Other Unix systems have no analogous commands; Solaris supports extended file attributes, but there are no user level commands for setting or changing them, and the chatr command in HP-UX, and chattr in AIX have unrelated functions.

chattr and lsattr utilities on Linux and the attributes they manipulate were originally specific to the Second Extended Filesystem family (ext2, ext3, ext4), and are available as part of the e2fsprogs package. The functionality has since been extended to many other Linux filesystems, including XFS, ReiserFS, JFS, OCFS2 and others, although not all filesystems support all flags. chflags is not specific to particular file systems; UFS on BSD systems, and HFS+, SMB, AFP, and FAT on OS X support chattr for at least some flags.

Among other things, the command can be used to make files immutable so that password files and certain system files cannot be erased during software upgrades.[1]

Description

The form of the chattr command is:

chattr [-RVf] [-+=AacDdijsSu] [-v version] files...
  • -R is to recurse all subdirectories
  • +i is to set the immutable bit to prevent even root from erasing or changing the contents of a file.
  • -i is to unset the immutable bit

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.

Attributes (chattr)

Some attributes include:

  • synchronous directory updates (D)
  • immutable (i)
  • data journaling (j)
  • secure deletion (s)

  • synchronous updates (S)
  • no tail-merging (t)
  • top of directory hierarchy (T)
  • undeletable (u)

Attributes (chflags)

Some attributes include:

  • set the archived flag (super-user only) - arch, archived
  • set the opaque flag (owner or super-user only). [Directory is opaque when viewed through a union mount] - opaque
  • set the nodump flag (owner or super-user only) - nodump
  • set the system append-only flag (super-user only) - sappnd, sappend
  • set the system immutable flag (super-user only) - schg, schange, simmutable
  • set the user append-only flag (owner or super-user only) - uappnd, uappend
  • set the user immutable flag (owner or super-user only) - uchg, uchange, uimmutable
  • set the hidden flag [Hide item from GUI] - hidden (OS X only)

See also

  • lsattr – view file attributes
  • chown – change file/directory ownership
  • chmod – change file access control attributes
  • cacls – Microsoft Windows NT file system ACL control utility

Notes

  1. chflags(1)  OpenBSD General Commands Manual
  2. E2fsprogs: add compress and cow support in chattr, lsattr, retrieved April 9, 2012 

References

This article is issued from Wikipedia. The text is available under the Creative Commons Attribution/Share Alike; additional terms may apply for the media files.