Chattr#In BSD-like systems (chflags)
{{Short description|Command in Linux}}
{{lowercase|title=chattr}}
{{Distinguish|Chatr}}
{{Infobox software
| name = chattr
| logo =
| screenshot =
| screenshot size =
| caption =
| author = Remy Card
| developer =
| released =
| latest release version =
| latest release date =
| operating system = Linux
| platform = Cross-platform
| genre = Command
| license =
| website =
}}
{{Infobox software
| name = chflags
| logo =
| screenshot =
| screenshot size =
| caption =
| author =
| developer =
| released =
| latest release version =
| latest release date =
| operating system = BSD-like systems, including macOS
| platform = Cross-platform
| genre = Command
| license =
| website =
}}
{{mono|chattr}} is the command in Linux that allows a user to set certain attributes of a file. {{mono|lsattr}} is the command that displays the attributes of a file.
Most BSD-like systems, including macOS, have always had an analogous {{mono|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{{man|1|chmod|OpenSolaris}} and ls{{man|1|ls|OpenSolaris}} are used instead.
Other Unix-like operating systems, in general, have no analogous commands. The similar-sounding commands {{mono|chatr}} (from HP-UX) and {{mono|lsattr}} (from AIX) exist but have unrelated functions.
Among other things, the {{mono|chattr}} command is useful to make files immutable so that password files and certain system files cannot be erased during software upgrades.{{man|1|chflags|OpenBSD}}
In Linux systems ({{mono|chattr}} and {{mono|lsattr}})
= File system support =
The command line tools {{mono|chattr}} (to manipulate attributes) and {{mono|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.
= {{mono|chattr}} description =
The form of the {{mono|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
= {{mono|lsattr}} description =
The form of the {{mono|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:
class="wikitable sortable" style="margin-left:auto; margin-right:auto"
|+ File attributes on a Linux file system according to the |
Attribute
!{{mono|lsattr}} flag !{{mono|chattr}} option !Semantics and rationale |
---|
No atime updates
|style="text-align:center" | | |
|
Append only
|style="text-align:center" | | |
|
Compressed
|style="text-align:center" | | |
|
No Copy-on-Write (CoW)
|style="text-align:center" | | |
|
Synchronous directory updates
|style="text-align:center" | | |
|
No dump
|style="text-align:center" | | |
|
Compression error
|style="text-align:center" | | {{n/a|(unavailable)}} |
|
Extent format
|style="text-align:center" | | {{n/a|(unavailable)}} |
|
Huge file
|style="text-align:center" | | {{n/a|(unavailable)}} |
|
Indexed directory
|style="text-align:center" | | {{n/a|(unavailable)}} |
|
Immutable
|style="text-align:center" | |
|
Data journaling
|style="text-align:center" | | |
|
Secure deletion
|style="text-align:center" | | |
|
Synchronous updates
|style="text-align:center" | | |
|
Top of directory hierarchy
|style="text-align:center" | | |
|
No tail-merging
|style="text-align:center" | | |
|
Undeletable
|style="text-align:center" | |
|
Compression raw access
|style="text-align:center" | | {{n/a|(unavailable)}} |
|
Compressed dirty file
|style="text-align:center" | | {{n/a|(unavailable)}} |
|
Version / generation number
|style="text-align:center" | |style="text-align:center" | |
|
== Notes ==
{{reflist|group=note}}
In BSD-like systems ({{mono|chflags}})
= File system support =
= {{mono|chflags}} description =
The form of the {{mono|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 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:
class="wikitable sortable" style="margin-left:auto; margin-right:auto"
|+ File attributes |
Attribute
!{{mono|ls}} flag !{{mono|chflags}} flag !Owner-settable !OS support !Semantics and rationale |
---|
Archived
|{{mono|arch}} |{{mono|arch}}, {{mono|archived}} |{{No}} |All |File is archived |
Opaque
|{{mono|opaque}} |{{mono|opaque}} |{{Yes}} |All |Directory is opaque when viewed through a union mount |
No dump
|{{mono|nodump}} |{{mono|nodump}} |{{Yes}} |All |File cannot be dumped |
System append-only
|{{mono|sappnd}} |{{mono|sappnd}}, {{mono|sappend}} |{{No}} |All |Existing data in the file can't be overwritten and the file cannot be truncated |
User append-only
|{{mono|uappnd}} |{{mono|uappnd}}, {{mono|uappend}} |{{Yes}} |All |Existing data in the file can't be overwritten and the file cannot be truncated |
System immutable
|{{mono|schg}} |{{mono|schg}}, {{mono|schange}}, {{mono|simmutable}} |{{No}} |All |File cannot be changed, renamed, moved, or removed |
User immutable
|{{mono|uchg}} |{{mono|uchg}}, {{mono|uchange}}, {{mono|uimmutable}} |{{Yes}} |All |File cannot be changed, renamed, moved, or removed |
System no-unlink
|{{mono|sunlnk}} |{{mono|sunlnk, sunlink}} |{{No}} |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
|{{mono|uunlnk}} |{{mono|uunlnk, uunlink}} |{{Yes}} |FreeBSD, DragonFly BSD |File cannot be removed, renamed or mounted on |
Hidden
|{{mono|hidden}} |{{mono|hidden}} |{{Yes}} |macOS |File is hidden by default in the GUI (but not in {{mono|ls}}) |
Hidden
|{{mono|hidden}} |{{mono|hidden, uhidden}} |{{Yes}} |FreeBSD |File might be hidden by default in some GUI desktops (but not in {{mono|ls}}) |
Tracked
|{{mono|tracked}} |{{mono|tracked}} |{{Yes}} |macOS |File modifications and deletions are tracked |
Restricted
|{{mono|restricted}} |{{mono|restricted}} |{{No}} |macOS |File is protected by System Integrity Protection; accompanied by the extended attribute {{mono|com.apple.rootless}}; flag needs to be set or cleared from Recovery Mode |
Compressed
|{{mono|compressed}} |{{mono |
|{{No}}
|macOS
|File is HFS-compressed (read-only flag); not available on APFS-formatted volumes
|-
!Data Vault
|{{mono|}}
|{{mono|}}
|{{No}}
|macOS
|Hidden privacy flag since macOS Mojave set by the core system to prohibit any access without special entitlements
|-
!Offline
|{{mono|offline}}
|{{mono|offline, uoffline}}
|{{Yes}}
|FreeBSD
|File is offline
|-
!Snapshot
|{{mono|snapshot}}
|
|{{No}}
|FreeBSD, NetBSD
|File is a snapshot file (read-only flag)
|-
!Sparse
|{{mono|sparse}}
|{{mono|sparse, usparse}}
|{{Yes}}
|FreeBSD
|Writes of all zeroes may be written as "holes"
|-
!Must be archived
|{{mono|uarch}}
|{{mono|uarch, uarchive}}
|{{Yes}}
|FreeBSD
|File must be archived
|-
|}
See also
Notes
{{reflist}}
References
- {{man|1|chattr|die.net}}
- {{man|1|lsattr|die.net}}
- {{man|1|chflags|OpenBSD}}
- {{man|1|chflags|FreeBSD}}
- {{man|1|chflags|NetBSD}}
- {{man|1|chflags|Darwin}} (outdated; see [https://www.unix.com/man-page/osx/1/chflags/ newer version])
- [https://github.com/apple/darwin-xnu/blob/master/bsd/sys/stat.h#L466-L519 {{mono|stat.h}}] (flags section in the BSD system source code of the macOS XNU kernel)
{{Unix commands}}