chattr | |
Author: | Remy Card |
Operating System: | Linux |
Platform: | Cross-platform |
Genre: | Command |
chflags | |
Operating System: | BSD-like systems, including macOS |
Platform: | Cross-platform |
Genre: | Command |
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.
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 C
flag, which turns off the built-in copy-on-write (CoW) feature of btrfs due to slower performance associated with CoW.
The form of the 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 messagesThe form of the 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 contentsSome attributes include:
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[1] |
|
Compressed | c | +c to set-c to clear[2] |
|
No Copy-on-Write (CoW) | C | +C to set-C to clear[3] |
|
Synchronous directory updates | D | +D to set-D to clear |
|
No dump | d | +d to set-d to clear |
|
Compression error | E |
| |
Extent format | e |
| |
Huge file | h |
| |
Indexed directory | I |
| |
Immutable | i | +i to set-i to clear |
|
Data journaling | j | +j to set-j to clear[4] |
|
Secure deletion | s | +s to set-s to clear[5] |
|
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 |
| |
Compressed dirty file | Z |
| |
Version / generation number | -v | -v ''version'' |
|
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.
The form of the command is:
-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.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 -lo
, or the -lO
, depending on the system, flags passed.
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 | FreeBSD, DragonFly BSD, macOS | 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 | FreeBSD, DragonFly BSD | File cannot be removed, renamed or mounted on | |||
Hidden | macOS, FreeBSD | File is hidden by default in the GUI (but not in) | |||
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 (read-only flag); 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 | |||
Offline | FreeBSD | File is offline | |||
Snapshot | FreeBSD, NetBSD | File is a snapshot file (read-only flag) | |||
Sparse | FreeBSD | Writes of all zeroes may be written as "holes" | |||
Must be archived | FreeBSD | File must be archived | |||
[[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 NTCAP_LINUX_IMMUTABLE
capability can set or clear these attributes.CAP_SYS_RESOURCE
capability can set or clear this attribute.