File attribute explained

File attributes are a type of meta-data that describe and may modify how files and/or directories in a filesystem 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 as FAT, 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 or file system permissions. In addition to files, folders, volumes and other file system objects may have attributes.

DOS and Windows

Traditionally, in DOS and Microsoft Windows, files and folders accepted four attributes:

As new versions of Windows came out, Microsoft has added to the inventory of available attributes on the NTFS file system, including but not limited to:[3]

Other attributes that are displayed in the "Attributes" column of Windows Explorer include:

In DOS, OS/2 and Windows, the [[attrib]] command in cmd.exe and command.com can be used to change and display the four traditional file attributes. File Explorer in Windows can show the seven mentioned attributes but cannot set or clear the System attribute. Windows PowerShell, which has become a component of Windows 7 and later, features two commands that can read and write attributes: Get-ItemProperty and Set-ItemProperty.[4] To change an attribute on a file on Windows NT, the user must have appropriate file system permissions known as Write Attributes and Write Extended Attributes.[5]

Unix and POSIX

In Unix and Unix-like systems, including POSIX-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 (see File-system permissions §Traditional Unix permissions for more details) plus the setuid and setgid bit flags and a 'sticky' bit flag.The mode also specifies the file type (regular file, directory, or some other special kind).

4.4BSD and derivatives

In 4.4BSD and 4.4BSD-Lite, files and directories (folders) accepted four attributes that could be set by the owner of the file or the superuser (the "User" attributes) and two attributes that could only be set by the superuser (the "System" attributes):

FreeBSD added some additional attributes, also supported by DragonFly BSD:

FreeBSD also supports:

whereas DragonFly BSD supports:

NetBSD added another attribute, also supported by OpenBSD:

macOS added three attributes:

In these systems, the [[chflags]] and [[ls]] 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.

Linux

The Linux operating system can support a wide range of file attributes that can be listed by the lsattr command and modified, where possible, by the [[chattr]] command.Programs can examine and alter attributes using ioctl operations.

Many Linux file systems support only a limited set of attributes, and none of them support every attribute that chattr can change. File systems that support at least some attributes include ext4, XFS and btrfs.

Common file attributes supported by many common Linux file systems
Attribute flag optionSemantics and rationale
No atime updatesA+A,-A record is not modified when file is read/accessed.
Append-onlya+a,-aWriting to file only allowed in append mode.
Immutablei+i,-iPrevents any change to file's contents or metadata: file/directory cannot be written to, deleted, renamed, or hard-linked.
No dumpd+d,-dFile is skipped by the program
Secure deletions+s,-sRequests that, when deleted, all file data blocks are filled with zeroes.
Synchronous updatesS+S,-SChanges are written synchronously to the underlying filesystem storage medium; equivalent to 'sync' mount option for affected files.

OpenSolaris and derivatives

Support for "system attributes" (in which the operating system defines the meaning, unlike general extended file attributes) was added to OpenSolaris in 2007 in support of the CIFS server.[6] It has been carried forward from there into both the Oracle Solaris 11 releases and the open source illumos project.

In this implementation, a wide range of attributes can be set via the [[chmod]] command[7] [8] and listed by the [[ls]] command.[9] [10] Programs can examine and alter attributes using the getattrat and setattrat functions.[11] [12]

Currently the ZFS file system supports all defined attributes, and starting in Oracle Solaris 11.2, the tmpfs file system supports a subset of attributes.[13]

Common file attributes supported by Oracle Solaris and illumos systems
AttributeCompact flag for & Semantics and rationale
appendonlyaWriting to file only allowed in append mode.
immutableiPrevents any change to file's contents or metadata (except access time): file/directory cannot be written to, deleted, or renamed.
nodumpdFile should be skipped by backup programs
nounlinkuPrevents removing the file, but allows other changes.

See also

External links

Notes and References

  1. Web site: What is a hidden file?. Windows 7 Help. Microsoft. 2 December 2012.
  2. Web site: Why is the readonly property on folders so strange?.
  3. Web site: HOW TO: Use the File Attribute Management Script (Fileattributes.pl) in Windows 2000. Microsoft support. Microsoft. 2 December 2012.
  4. Web site: Use a PowerShell Cmdlet to Work with File Attributes. Hey, Scripting Guy! Blog. Microsoft. 3 December 2012. 26 January 2011.
  5. Web site: How to set, view, change, or remove special permissions for files and folders in Windows XP. Microsoft Support. Microsoft. 2 December 2012. 7 May 2007.
  6. Web site: Shellenbaum . Mark . Extensible Attribute Interfaces [PSARC/2007/315] ]. OpenSolaris ARC Material Archive . illumos.org . 10 March 2023.
  7. Web site: chmod(1) . Oracle Solaris 11.4 Reference Library: man pages section 1: User Commands . Oracle . 10 March 2023.
  8. Web site: chmod(1) . illumos man pages . illumos.org . 10 March 2023.
  9. Web site: ls(1) . Oracle Solaris 11.4 Reference Library: man pages section 1: User Commands . Oracle . 10 March 2023.
  10. Web site: ls(1) . illumos man pages . illumos.org . 10 March 2023.
  11. Web site: getattrat(3c)/setattrat(3c) . Oracle Solaris 11.4 Reference Library: man pages section 3: Basic Library Functions . Oracle . 10 March 2023.
  12. Web site: getattrat(3c)/setattrat(3c) . illumos man pages . illumos.org . 10 March 2023.
  13. Web site: sysattr(7) . Oracle Solaris 11.4 Reference Library: man pages section 7 . Oracle . 10 March 2023.