File attributes are a type ofmetadata that describe and may modify howfiles and/ordirectories in afilesystem behave. Typical file attributes may, for example, indicate or specify whether a file is visible, modifiable, compressed, or encrypted. The availability of most file attributes depends on support by the underlying filesystem (such asFAT,NTFS,ext4) where attribute data must be stored along with other control structures. Each attribute can have one of two states: set and cleared. Attributes are considered distinct from other metadata, such as dates and times,filename extensions orfile system permissions. In addition to files,folders,volumes and other file system objects may have attributes.
Traditionally, inDOS andMicrosoft Windows,files andfolders accepted four attributes:[1][2][3]
dir and Windows apps likeFile Explorer do not show hidden files by default, unless asked to do so.[4]dir and Windows apps like File Explorer do not show system files by default even when hidden files are shown, unless asked to do so.As new versions of Windows came out, Microsoft has added to the inventory of available attributes on theNTFS file system,[7] including but not limited to:[8]
Other attributes that are displayed in the "Attributes" column of Windows Explorer[7] include:
In DOS,OS/2 and Windows, theattrib command incmd.exe andcommand.com can be used to change and display the four traditional file attributes.[3][9] File Explorer in Windows can show the seven mentioned attributes but cannot set or clear the System attribute.[5]Windows PowerShell, which has become a component ofWindows 7 and later, features two commands that can read and write attributes:Get-ItemProperty andSet-ItemProperty.[10] To change an attribute on a file onWindows NT, the user must have appropriatefile system permissions known asWrite Attributes andWrite Extended Attributes.[11]
InUnix and Unix-like systems, includingPOSIX-conforming systems, each file has a 'mode' containing 9 bit flags controlling read, write and execute permission for each of the file's owner, group and all other users (seeFile-system permissions §Traditional Unix permissions for more details) plus thesetuid andsetgid bit flags and a'sticky' bit flag.The mode also specifies thefile type (regular file, directory, or some other special kind).
In4.4BSD and4.4BSD-Lite, files and directories (folders) accepted four attributes that could be set by the owner of the file or thesuperuser (the "User" attributes) and two attributes that could only be set by the superuser (the "System" attributes):[12]
FreeBSD added some additional attributes,[13] also supported byDragonFly BSD:[14]
FreeBSD also supports:[13]
whereas DragonFly BSD supports:[14]
NetBSD added another attribute,[15] also supported byOpenBSD:[16]
macOS added three attributes:
In these systems, thechflags andls commands can be used to change and display file attributes. To change a "user" attribute on a file in 4.4BSD-derived operating systems, the user must be the owner of the file or the superuser; to change a "system" attribute, the user must be the superuser.
TheLinux operating system can support awide range of file attributes that can be listed by thelsattr command and modified, where possible, by thechattr command.Programs can examine and alter attributes usingioctl operations.[18]
Many Linux file systems support only a limited set of attributes, and none of them support every attribute thatchattr can change. File systems that support at least some attributes includeext4,XFS andbtrfs.
| Attribute | lsattr flag | chattr option | Semantics and rationale |
|---|---|---|---|
Noatime updates | A | +A,-A | atime record is not modified when file is read/accessed. |
| Append-only | a | +a,-a | Writing to file only allowed in append mode. |
| Immutable | i | +i,-i | Prevents any change to file's contents or metadata: file/directory cannot be written to, deleted, renamed, or hard-linked. |
| No dump | d | +d,-d | File is skipped by thedump program |
| Secure deletion | s | +s,-s | Requests that, when deleted, all file data blocks arefilled with zeroes. |
| Synchronous updates | S | +S,-S | Changes are written synchronously to the underlying filesystem storage medium; equivalent to 'sync' mount option for affected files. |
Support for "system attributes" (in which the operating system defines the meaning, unlike generalextended file attributes) was added to OpenSolaris in 2007 in support of the CIFS server.[19] It has been carried forward from there into both theOracle Solaris 11 releases and the open sourceillumos project.
In this implementation, awide range of attributes can be set via thechmod command[20][21] and listed by thels command.[22][23]Programs can examine and alter attributes using thegetattrat andsetattrat functions.[24][25]
Currently theZFS file system supports all defined attributes, and starting in Oracle Solaris 11.2, thetmpfs file system supports a subset of attributes.[26]
| Attribute | Compact flag forls &chmod | Semantics and rationale |
|---|---|---|
appendonly | a | Writing to file only allowed in append mode. |
immutable | i | Prevents any change to file's contents or metadata (except access time): file/directory cannot be written to, deleted, or renamed. |
nodump | d | File should be skipped by backup programs |
nounlink | u | Prevents removing the file, but allows other changes. |
chflags(2) – BSD System CallsManualchflags(2) – FreeBSD System CallsManualchflags(2) – DragonFly BSD System Calls and Error NumbersManualchflags(2) – NetBSD System CallsManualchflags(2) – OpenBSD System CallsManualchflags(2) – Darwin andmacOS System CallsManualioctl_iflags(2) – Linux Programmer'sManual – System Calls from Manned.org