chattr

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search

Template:Short description

Script error: No such module "Distinguish". Script error: No such module "Infobox". Script error: No such module "Check for unknown parameters".Script error: No such module "Check for conflicting parameters". Script error: No such module "Infobox". Script error: No such module "Check for unknown parameters".Script error: No such module "Check for conflicting parameters". <templatestyles src="Mono/styles.css" />chattr is the command in Linux that allows a user to set certain attributes of a file. <templatestyles src="Mono/styles.css" />lsattr is the command that displays the attributes of a file.

Most BSD-like systems, including macOS, have always had an analogous <templatestyles src="Mono/styles.css" />chflags command to set the attributes, but no command specifically meant to display them; specific options to the <templatestyles src="Mono/styles.css" />ls command are used instead. The chflags command first appeared in 4.4BSD.

Solaris has no commands specifically meant to manipulate them. <templatestyles src="Mono/styles.css" />chmod[1] and <templatestyles src="Mono/styles.css" />ls[2] are used instead.

Other Unix-like operating systems, in general, have no analogous commands. The similar-sounding commands <templatestyles src="Mono/styles.css" />chatr (from HP-UX) and <templatestyles src="Mono/styles.css" />lsattr (from AIX) exist but have unrelated functions.

Among other things, the <templatestyles src="Mono/styles.css" />chattr command is useful to make files immutable so that password files and certain system files cannot be erased during software upgrades.[3]

In Linux systems (<templatestyles src="Mono/styles.css" />chattr and <templatestyles src="Mono/styles.css" />lsattr)

File system support

The command line tools <templatestyles src="Mono/styles.css" />chattr (to manipulate attributes) and <templatestyles src="Mono/styles.css" />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.

<templatestyles src="Mono/styles.css" />chattr description

The form of the <templatestyles src="Mono/styles.css" />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

<templatestyles src="Mono/styles.css" />lsattr description

The form of the <templatestyles src="Mono/styles.css" />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:

File attributes on a Linux file system according to the chattr(1) Linux man page
Attribute <templatestyles src="Mono/styles.css" />lsattr flag <templatestyles src="Mono/styles.css" />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]
  • A file with the a attribute set can only be open in append mode for writing.
Compressed c +c to set
-c to clear[note 2]
  • A file with the c attribute set is automatically compressed on the disk by the kernel.
  • A read from this file returns uncompressed data.
  • A write to this file compresses data before storing them on the disk.
No Copy-on-Write (CoW) C +C to set
-C to clear[note 3]
  • A file with the C attribute will not be subject to Copy-on-Write updates.
  • Updates to these files may not be subject to atomic snapshots, and may lack some reliability information on some filesystems and kernels.
Synchronous directory updates D +D to set
-D to clear
  • When a directory with the D attribute set is modified, the changes are written synchronously on the disk
  • This is equivalent to the dirsync mount option, applied to a subset of the files.
No dump d +d to set
-d to clear
Compression error E (unavailable)
  • The E attribute is used by the experimental compression patches to indicate that a compressed file has a compression error.
Extent format e (unavailable)
  • The e attribute indicates that the file is using extents for mapping the blocks on disk.
Huge file h (unavailable)
  • The h attribute indicates the file is storing its blocks in units of the filesystem blocksize instead of in units of sectors.
  • It means that the file is, or at one time was, larger than 2TB.
Indexed directory I (unavailable)
Immutable i +i to set
-i to clear[note 1]
  • A file with the i attribute cannot be modified.
  • It cannot be deleted or renamed, no link can be created to this file and no data can be written to the file.
  • When set, prevents, even the superuser, from erasing or changing the contents of the file.
Data journaling j +j to set
-j to clear[note 4]
  • A file with the j attribute has all of its data written to the <templatestyles src="Mono/styles.css" />ext3 journal before being written to the file itself, if the filesystem is mounted with the "data=ordered" or "data=writeback" options.
  • When the filesystem is mounted with the "data=journal" option all file data is already journaled, so this attribute has no effect.
Secure deletion s +s to set
-s to clear[note 2][note 5]
Synchronous updates S +S to set
-S to clear
  • When a file with the S attribute set is modified, the changes are written synchronously on the disk; this is equivalent to the 'sync' mount option applied to a subset of the files.
  • This is equivalent to the sync mount option, applied to a subset of the files.
Top of directory hierarchy T +T to set
-T to clear
  • A directory with the T attribute will be deemed to be the top of directory hierarchies for the purposes of the Orlov block allocator.
  • This is a hint to the block allocator used by <templatestyles src="Mono/styles.css" />ext3 and <templatestyles src="Mono/styles.css" />ext4 that the subdirectories under this directory are not related, and thus should be spread apart for allocation purposes.
  • For example: it is a very good idea to set the T attribute on the /home directory, so that /home/john and /home/mary are placed into separate block groups.
  • For directories where this attribute is not set, the Orlov block allocator will try to group subdirectories closer together where possible.
No tail-merging t +t to set
-t to clear
  • For those filesystems that support tail-merging, a file with the t attribute will not have a partial block fragment at the end of the file merged with other files.
  • This is necessary for applications such as LILO, which reads the filesystem directly and doesn't understand tail-merged files.
Undeletable u +u to set
-u to clear[note 2]
  • When a file with the u attribute set is deleted, its contents are saved.
  • This allows the user to ask for its undeletion.
Compression raw access X (unavailable)
  • The X attribute is used by the experimental compression patches to indicate that a raw contents of a compressed file can be accessed directly.
Compressed dirty file Z (unavailable)
  • The Z attribute is used by the experimental compression patches to indicate a compressed file is "dirty".
Version / generation number -v -v version
  • File's version/generation number.

Notes

<templatestyles src="Reflist/styles.css" />

  1. a b Only the superuser or a process possessing the CAP_LINUX_IMMUTABLE capability can set or clear these attributes.
  2. a b c These attributes are not honored by the <templatestyles src="Mono/styles.css" />ext2 and <templatestyles src="Mono/styles.css" />ext3 filesystems as implemented in the current mainline Linux kernels.
  3. These attributes only make sense for Copy-on-Write file-systems such as <templatestyles src="Mono/styles.css" />btrfs.
  4. Only the superuser or a process possessing the CAP_SYS_RESOURCE capability can set or clear this attribute.
  5. This attribute is not honored by the <templatestyles src="Mono/styles.css" />ext4 filesystem as implemented in the current mainline Linux kernels as reported in Bug #17872.

Script error: No such module "Check for unknown parameters".

In BSD-like systems (<templatestyles src="Mono/styles.css" />chflags)

File system support

The <templatestyles src="Mono/styles.css" />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.

<templatestyles src="Mono/styles.css" />chflags description

The form of the <templatestyles src="Mono/styles.css" />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 <templatestyles src="Mono/styles.css" />ls command 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:

File attributes
Attribute <templatestyles src="Mono/styles.css" />ls flag <templatestyles src="Mono/styles.css" />chflags flag Owner-settable OS support Semantics and rationale
Archived <templatestyles src="Mono/styles.css" />arch <templatestyles src="Mono/styles.css" />arch, <templatestyles src="Mono/styles.css" />archived No All File is archived
Opaque <templatestyles src="Mono/styles.css" />opaque <templatestyles src="Mono/styles.css" />opaque Yes All Directory is opaque when viewed through a union mount
No dump <templatestyles src="Mono/styles.css" />nodump <templatestyles src="Mono/styles.css" />nodump Yes All File cannot be dumped
System append-only <templatestyles src="Mono/styles.css" />sappnd <templatestyles src="Mono/styles.css" />sappnd, <templatestyles src="Mono/styles.css" />sappend No All Existing data in the file can't be overwritten and the file cannot be truncated
User append-only <templatestyles src="Mono/styles.css" />uappnd <templatestyles src="Mono/styles.css" />uappnd, <templatestyles src="Mono/styles.css" />uappend Yes All Existing data in the file can't be overwritten and the file cannot be truncated
System immutable <templatestyles src="Mono/styles.css" />schg <templatestyles src="Mono/styles.css" />schg, <templatestyles src="Mono/styles.css" />schange, <templatestyles src="Mono/styles.css" />simmutable No All File cannot be changed, renamed, moved, or removed
User immutable <templatestyles src="Mono/styles.css" />uchg <templatestyles src="Mono/styles.css" />uchg, <templatestyles src="Mono/styles.css" />uchange, <templatestyles src="Mono/styles.css" />uimmutable Yes All File cannot be changed, renamed, moved, or removed
System no-unlink <templatestyles src="Mono/styles.css" />sunlnk <templatestyles src="Mono/styles.css" />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 <templatestyles src="Mono/styles.css" />uunlnk <templatestyles src="Mono/styles.css" />uunlnk, uunlink Yes FreeBSD, DragonFly BSD File cannot be removed, renamed or mounted on
Hidden <templatestyles src="Mono/styles.css" />hidden <templatestyles src="Mono/styles.css" />hidden Yes macOS File is hidden by default in the GUI (but not in <templatestyles src="Mono/styles.css" />ls)
Hidden <templatestyles src="Mono/styles.css" />hidden <templatestyles src="Mono/styles.css" />hidden, uhidden Yes FreeBSD File might be hidden by default in some GUI desktops (but not in <templatestyles src="Mono/styles.css" />ls)
Tracked <templatestyles src="Mono/styles.css" />tracked <templatestyles src="Mono/styles.css" />tracked Yes macOS File modifications and deletions are tracked
Restricted <templatestyles src="Mono/styles.css" />restricted <templatestyles src="Mono/styles.css" />restricted No macOS File is protected by System Integrity Protection; accompanied by the extended attribute <templatestyles src="Mono/styles.css" />com.apple.rootless; flag needs to be set or cleared from Recovery Mode
Compressed <templatestyles src="Mono/styles.css" />compressed <templatestyles src="Mono/styles.css" /> No macOS File is HFS-compressed (read-only flag); not available on APFS-formatted volumes
Data Vault <templatestyles src="Mono/styles.css" /> <templatestyles src="Mono/styles.css" /> No macOS Hidden privacy flag since macOS Mojave set by the core system to prohibit any access without special entitlements
Offline <templatestyles src="Mono/styles.css" />offline <templatestyles src="Mono/styles.css" />offline, uoffline Yes FreeBSD File is offline
Snapshot <templatestyles src="Mono/styles.css" />snapshot No FreeBSD, NetBSD File is a snapshot file (read-only flag)
Sparse <templatestyles src="Mono/styles.css" />sparse <templatestyles src="Mono/styles.css" />sparse, usparse Yes FreeBSD Writes of all zeroes may be written as "holes"
Must be archived <templatestyles src="Mono/styles.css" />uarch <templatestyles src="Mono/styles.css" />uarch, uarchive Yes FreeBSD File must be archived

See also

  • 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 NT

Notes

<templatestyles src="Reflist/styles.css" />

  1. [[[:Template:Man/OpenSolaris]] chmod(Template:Man/OpenSolaris)] – Template:Man/OpenSolaris
  2. [[[:Template:Man/OpenSolaris]] ls(Template:Man/OpenSolaris)] – Template:Man/OpenSolaris
  3. chflags(1) – OpenBSD General Commands Manual

Script error: No such module "Check for unknown parameters".

References

Script error: No such module "Navbox".