Chattr: Difference between revisions
→In Linux systems ({{mono|chattr}} and {{mono|lsattr}}): changed "write-on-copy" to "copy-on-write" |
→Attributes: Include +C noCoW as a top-level attribute as it has made it into the chattr manpage |
||
Line 76: | Line 76: | ||
*A read from this file returns uncompressed data. |
*A read from this file returns uncompressed data. |
||
*A write to this file compresses data before storing them on the disk. |
*A write to this file compresses data before storing them on the disk. |
||
|- |
|||
!No Copy-on-Write (CoW) |
|||
|style="text-align:center" |<code>C</code> |
|||
|<code>+C</code> to set<br /><code>-C</code> to clear<ref name=cow_only group=note>These attributes only make sense for Copy-on-Write file-systems such as {{boldmono|[[btrfs]]}}.</ref> |
|||
| |
|||
*A file with the <code>C</code> 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 |
!Synchronous directory updates |
||
Line 189: | Line 197: | ||
{{reflist|group=note}} |
{{reflist|group=note}} |
||
==== Other attributes ==== |
|||
Other attributes include: |
|||
{{col-begin}} |
|||
{{col-3}} |
|||
* no [[Copy-on-write]] (C) <ref>{{Citation|url=http://www.spinics.net/lists/linux-btrfs/msg09605.html|title=E2fsprogs: add compress and cow support in chattr, lsattr|accessdate=April 9, 2012}}</ref> The btrfs file system includes the use of the C attribute. |
|||
{{col-3}} |
|||
{{col-3}} |
|||
{{col-end}} |
|||
== In BSD-like systems ({{mono|chflags}}) == |
== In BSD-like systems ({{mono|chflags}}) == |
Revision as of 10:30, 16 September 2017
Template:Boldmono is the command in the Linux operating system that allows a user to set certain attributes of a file residing on a Linux file system. Template:Boldmono is the command that displays the attributes of a file.
Modern BSD-like systems, including OS X, have analogous Template:Boldmono to set, but no command specifically meant to display them; specific options to the ls command are used instead.
The Solaris system has no commands specifically meant to manipulate them. chmodCite error: The <ref>
tag has too many names (see the help page). and lsCite error: The <ref>
tag has too many names (see the help page). are used instead.
Other Unices, 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.[1]
In Linux systems (chattr and lsattr)
File system support
The attributes chattr and lsattr manipulate 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 C which turns off the copy-on-write built in feature of btrfs due to slower performance associated with CoW.
Even the originally targeted file systems miss some features, as pointed further in this article.
chattr description
The form of the Template:Boldmono 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
lsattr description
The form of the Template:Boldmono 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:
Attribute | Template:Boldmono flag | Template:Boldmono 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
|
|
Notes
- ^ a b Only the superuser or a process possessing the
CAP_LINUX_IMMUTABLE
capability can set or clear these attributes. - ^ a b c These attributes are not honored by the Template:Boldmono and Template:Boldmono filesystems as implemented in the current mainline Linux kernels.
- ^ These attributes only make sense for Copy-on-Write file-systems such as Template:Boldmono.
- ^ Only the superuser or a process possessing the
CAP_SYS_RESOURCE
capability can set or clear this attribute. - ^ This attribute is not honored by the Template:Boldmono filesystem as implemented in the current mainline Linux kernels as reported in Bug #17872.
In BSD-like systems (chflags)
File system support
The chflags command is not specific to particular file systems. UFS on BSD systems, and HFS+, SMB, AFP, and FAT on OS X support least some flags.
chflags description
The form of the Template:Boldmono 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 command will do with either the -lo
, or the -lO
, depending on the system, flags passed.
Attributes
All 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 | |
Opaque | opaque | opaque | Yes | All | Directory is opaque when viewed through a union mount |
No dump | nodump | nodump | Yes | All | |
System append-only | sappnd | sappnd, sappend | No | 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 append-only | uappnd | uappnd, uappend | Yes | All | Existing data in the file can't be overwritten and the file cannot be truncated |
User immutable | uchg | uchg, uchange, uimmutable | Yes | All | Existing data in the file can't be overwritten |
Hidden | hidden | hidden | Yes | OS X | File is hidden by default in the GUI (but not in ls) |
See also
ATTRIB
– analogous command in MS-DOS, OS/2 and Microsoft Windowschown
– change file/directory ownership in a Unix systemchmod
– change file access control attributes in a Unix systemcacls
– change file access control lists in Microsoft Windows NT