my-server
← Wiki Redirected from Chflags

Chattr

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

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

Solaris has no commands specifically meant to manipulate them. and are used instead.

Other Unix-like operating systems, in general, have no analogous commands. The similar-sounding commands (from HP-UX) and (from AIX) exist but have unrelated functions.

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

In Linux systems ( and )

File system support

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

description

The form of the command is:

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

description

The form of the command (gnu 1.41.3):

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

Attributes

Some attributes include:

Notes

In BSD-like systems ()

File system support

The 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.

description

The form of the command is:

  • <code>-H</code> If the -R option is specified, symbolic links on the command line are followed. (Symbolic links encountered in the tree traversal are not followed.)
  • <code>-L</code> If the -R option is specified, all symbolic links are followed.
  • <code>-P</code> If the -R option is specified, no symbolic links are followed. This is the default.
  • <code>-R</code> 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 command will do with either the <code>-lo</code>, or the <code>-lO</code>, 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:

See also

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

Notes

References

  • (outdated; see newer version)
  • (flags section in the BSD system source code of the macOS XNU kernel)