Chattr
' is the command in the GNU operating system 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 ls| command are used instead.
Solaris has no commands specifically meant to manipulate them. chmod| and ls| are used instead.
Other Unixes, in general, have no analogous commands. The similar-sounding commands and 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 [GNU]/Linux systems">Linux">Linux systems ( and )
File system support
The command line tools and were originally specific to the Second Extended Filesystem family, 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 feature of btrfs due to slower performance associated with CoW.description
The form of the command is:chattr files...
-
-R
recursively changes attributes of directories and their contents -
-V
is to be verbose and print the program version -
-f
suppresses most error messagesdescription
lsattr
-
-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 contentsAttributes
Attribute | flag | option | Semantics and rationale |
No atime updates | A | +A to set-A to clear |
|
Append only | a | +a to set-a to clear |
|
Compressed | c | +c to set-c to clear |
|
No Copy-on-Write | C | +C to set-C to clear |
|
Synchronous directory updates | D | +D to set-D to clear |
|
No dump | d | +d to set-d to clear |
|
Compression error | E | E attribute is used by the experimental compression patches to indicate that a compressed file has a compression error. | |
Extent format | e | e attribute indicates that the file is using extents for mapping the blocks on disk. | |
Huge file | h | h attribute indicates the file is storing its blocks in units of the filesystem blocksize instead of in units of sectors. | |
Indexed directory | I | I attribute is used by the program code to indicate that a directory is being indexed using hashed trees. | |
Immutable | i | +i to set-i to clear |
|
Data journaling | j | +j to set-j to clear |
|
Secure deletion | s | +s to set-s to clear |
|
Synchronous updates | S | +S to set-S to clear |
|
Top of directory hierarchy | T | +T to set-T to clear |
|
No tail-merging | t | +t to set-t to clear |
|
Undeletable | u | +u to set-u to clear |
|
Compression raw access | X | X attribute is used by the experimental compression patches to indicate that a raw contents of a compressed file can be accessed directly. | |
Compressed dirty file | Z | Z attribute is used by the experimental compression patches to indicate a compressed file is "dirty". | |
Version / generation number | -v | -v version |
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 least some flags.description
The form of the command is:chflags [-R [-H | -L | -P flags file...
-
-H
If the -R option is specified, symbolic links on the command line are 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
-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:
Attribute | flag | flag | Owner-settable | OS support | Semantics and rationale |
Archived | , | All | File is archived | ||
Opaque | All | Directory is opaque when viewed through a union mount | |||
No dump | All | File cannot be dumped | |||
System append-only | , | All | Existing data in the file can't be overwritten and the file cannot be truncated | ||
User append-only | , | All | Existing data in the file can't be overwritten and the file cannot be truncated | ||
System immutable | ,, | All | File cannot be changed, renamed, moved, or removed | ||
User immutable | ,, | All | File cannot be changed, renamed, moved, or removed | ||
System no-unlink | All | File cannot be removed, renamed or mounted on; on macOS this flag needs to be set or cleared from single user mode | |||
User no-unlink | Some | File cannot be removed, renamed or mounted on; not supported by macOS | |||
Hidden | FreeBSD | File is hidden by default in the GUI | |||
User hidden | FreeBSD | File is hidden by default in the GUI | |||
Hidden | macOS | File is hidden by default in the GUI | |||
Tracked | macOS | File modifications and deletions are tracked | |||
Restricted | macOS | File is protected by System Integrity Protection; accompanied by the extended attribute ; flag needs to be set or cleared from Recovery Mode | |||
Compressed | macOS | File is HFS-compressed ; not available on APFS-formatted volumes | |||
Data Vault | macOS | Hidden privacy flag since macOS Mojave set by the core system to prohibit any access without special entitlements |
BSD systems offer additional flags like offline, snapshot, sparse, and uarchive; see References.