Original author(s) | Remy Card |
---|---|
Operating system | Linux |
Platform | Cross-platform |
Type | Command |
Operating system | BSD-like systems, including macOS |
---|---|
Platform | Cross-platform |
Type | Command |
chattr is the command in Linux that allows a user to set certain attributes of a file. lsattr is the command that displays the attributes of a file.
Most BSD-like systems, including macOS, have always had an analogous 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 [1] and ls [2] are used instead.
Other Unix-like operating systems, in general, have no analogous commands. The similar-sounding commands chatr (from HP-UX) and lsattr (from AIX) exist but have unrelated functions.
Among other things, the chattr command is useful to make files immutable so that password files and certain system files cannot be erased during software upgrades. [3]
The command line tools chattr (to manipulate attributes) and 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.
The form of the chattr command is:
chattr[-RVf][-+=AacDdijsTtSu][-vversion]files...
-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 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 contentsSome attributes include:
Attribute | lsattr flag | chattr option | Semantics and rationale |
---|---|---|---|
No atime updates | A | +A to set-A to clear |
|
Append only | a | +a to set-a to clear [note 1] |
|
Compressed | c | +c to set-c to clear [note 2] |
|
No Copy-on-Write (CoW) | C | +C to set-C to clear [note 3] |
|
Synchronous directory updates | D | +D to set-D to clear |
|
No dump | d | +d to set-d to clear |
|
Compression error | E | (unavailable) |
|
Extent format | e | (unavailable) |
|
Huge file | h | (unavailable) |
|
Indexed directory | I | (unavailable) |
|
Immutable | i | +i to set-i to clear [note 1] |
|
Data journaling | j | +j to set-j to clear [note 4] |
|
Secure deletion | s | +s to set-s to clear [note 2] [note 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 [note 2] |
|
Compression raw access | X | (unavailable) |
|
Compressed dirty file | Z | (unavailable) |
|
Version / generation number | -v | -v version |
|
CAP_LINUX_IMMUTABLE
capability can set or clear these attributes.CAP_SYS_RESOURCE
capability can set or clear this attribute.The chflags 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 chflags command is:
chflags[-R[-H|-L|-P]]flagsfile...
-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 ls 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 | ls flag | chflags flag | Owner-settable | OS support | Semantics and rationale |
---|---|---|---|---|---|
Archived | arch | arch, archived | No | All | File is archived |
Opaque | opaque | opaque | Yes | All | Directory is opaque when viewed through a union mount |
No dump | nodump | nodump | Yes | All | File cannot be dumped |
System append-only | sappnd | sappnd, sappend | No | All | Existing data in the file can't be overwritten and the file cannot be truncated |
User append-only | uappnd | uappnd, uappend | Yes | All | Existing data in the file can't be overwritten and the file cannot be truncated |
System immutable | schg | schg, schange, simmutable | No | All | File cannot be changed, renamed, moved, or removed |
User immutable | uchg | uchg, uchange, uimmutable | Yes | All | File cannot be changed, renamed, moved, or removed |
System no-unlink | sunlnk | 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 | uunlnk | uunlnk, uunlink | Yes | FreeBSD, DragonFly BSD | File cannot be removed, renamed or mounted on |
Hidden | hidden | hidden | Yes | macOS | File is hidden by default in the GUI (but not in ls) |
Hidden | hidden | hidden, uhidden | Yes | FreeBSD | File might be hidden by default in some GUI desktops (but not in ls) |
Tracked | tracked | tracked | Yes | macOS | File modifications and deletions are tracked |
Restricted | restricted | restricted | No | macOS | File is protected by System Integrity Protection; accompanied by the extended attribute com.apple.rootless; flag needs to be set or cleared from Recovery Mode |
Compressed | compressed | No | macOS | File is HFS-compressed (read-only flag); not available on APFS-formatted volumes | |
Data Vault | No | macOS | Hidden privacy flag since macOS Mojave set by the core system to prohibit any access without special entitlements | ||
Offline | offline | offline, uoffline | Yes | FreeBSD | File is offline |
Snapshot | snapshot | No | FreeBSD, NetBSD | File is a snapshot file (read-only flag) | |
Sparse | sparse | sparse, usparse | Yes | FreeBSD | Writes of all zeroes may be written as "holes" |
Must be archived | uarch | uarch, uarchive | Yes | FreeBSD | File must be archived |
ext2, or second extended file system, is a file system for the Linux kernel. It was initially designed by French software developer Rémy Card as a replacement for the extended file system (ext). Having been designed according to the same principles as the Berkeley Fast File System from BSD, it was the first commercial-grade filesystem for Linux.
ext3, or third extended filesystem, is a journaled file system that is commonly used with the Linux kernel. It used to be the default file system for many popular Linux distributions but generally has been supplanted by its successor version ext4. The main advantage of ext3 over its predecessor, ext2, is journaling, which improves reliability and eliminates the need to check the file system after an improper, a.k.a. unclean, shutdown.
In Unix and Unix-like operating systems, chmod is the command and system call used to change the access permissions and the special mode flags of file system objects. Collectively these were originally called its modes, and the name chmod was chosen as an abbreviation of change mode.
The system utility fsck
is a tool for checking the consistency of a file system in Unix and Unix-like operating systems, such as Linux, macOS, and FreeBSD. The equivalent programs on MS-DOS and Microsoft Windows are CHKDSK, SFC, and SCANDISK.
The Unix file system (UFS) is a family of file systems supported by many Unix and Unix-like operating systems. It is a distant descendant of the original filesystem used by Version 7 Unix.
fstab is a system file commonly found in the directory /etc
on Unix and Unix-like computer systems. In Linux, it is part of the util-linux package. The fstab file typically lists all available disk partitions and other types of file systems and data sources that may not necessarily be disk-based, and indicates how they are to be initialized or otherwise integrated into the larger file system structure.
In computing, a file system or filesystem governs file organization and access. A local file system is a capability of an operating system that services the applications running on the same computer. A distributed file system is a protocol that provides file access between networked computers.
Most file systems include attributes of files and directories that control the ability of users to read, change, navigate, and execute the contents of the file system. In some cases, menu options or functions may be made visible or hidden depending on a user's permission level; this kind of user interface is referred to as permission-driven.
rm
is a basic command on Unix and Unix-like operating systems used to remove objects such as computer files, directories and symbolic links from file systems and also special files such as device nodes, pipes and sockets, similar to the del
command in MS-DOS, OS/2, and Microsoft Windows. The command is also available in the EFI shell.
The proc filesystem (procfs) is a special filesystem in Unix-like operating systems that presents information about processes and other system information in a hierarchical file-like structure, providing a more convenient and standardized method for dynamically accessing process data held in the kernel than traditional tracing methods or direct access to kernel memory. Typically, it is mapped to a mount point named /proc at boot time. The proc file system acts as an interface to internal data structures about running processes in the kernel. In Linux, it can also be used to obtain information about the kernel and to change certain kernel parameters at runtime (sysctl).
File attributes are a type of metadata 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 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.
In computing, the sticky bit is a user ownership access right flag that can be assigned to files and directories on Unix-like systems.
Extended file attributes are file system features that enable users to associate computer files with metadata not interpreted by the filesystem, whereas regular attributes have a purpose strictly defined by the filesystem. Unlike forks, which can usually be as large as the maximum file size, extended attributes are usually limited in size to a value significantly smaller than the maximum file size. Typical uses include storing the author of a document, the character encoding of a plain-text document, or a checksum, cryptographic hash or digital certificate, and discretionary access control information.
The following tables compare general and technical information for a number of file systems.
e2fsprogs is a set of utilities for maintaining the ext2, ext3 and ext4 file systems. Since those file systems are often the default for Linux distributions, it is commonly considered to be essential software.
ext4 is a journaling file system for Linux, developed as the successor to ext3.
In computer operating systems, mkfs
is a command used to format a block storage device with a specific file system. The command is part of Unix and Unix-like operating systems. In Unix, a block storage device must be formatted with a file system before it can be mounted and accessed through the operating system's filesystem hierarchy.
The Orlov block allocator is an algorithm to define where a particular file will reside on a given file system (blockwise), so as to speed up disk operations.
In Unix and operating systems inspired by it, the file system is considered a central component of the operating system. It was also one of the first parts of the system to be designed and implemented by Ken Thompson in the first experimental version of Unix, dated 1969.