Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

chattr

From Wikipedia, the free encyclopedia
Command in Linux
Not to be confused withChatr.
chattr
Original author(s)Remy Card
Operating systemLinux
PlatformCross-platform
TypeCommand
chflags
Operating systemBSD-like systems, includingmacOS
PlatformCross-platform
TypeCommand

chattr is thecommand inLinux that allows a user to set certainattributes of a file.lsattr is the command that displays the attributes of a file.

MostBSD-like systems, includingmacOS, have always had an analogouschflags command to set the attributes, but no command specifically meant to display them; specific options to thels command are used instead. The chflags command first appeared in4.4BSD.

Solaris has no commands specifically meant to manipulate them.chmod[1] andls[2] are used instead.

OtherUnix-like operating systems, in general, have no analogous commands. The similar-sounding commandschatr (fromHP-UX) andlsattr (fromAIX) exist but have unrelated functions.

Among other things, thechattr 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 (chattr andlsattr)

[edit]

File system support

[edit]

The command line toolschattr (to manipulate attributes) andlsattr (to list attributes) were originally specific to the Second Extended Filesystem family (ext2,ext3,ext4), and are available as part of thee2fsprogs package.

However, the functionality has since been extended, fully or partially, to many other systems, includingXFS,ReiserFS,JFS andOCFS2. The btrfs file system includes the attribute functionality, including theC flag, which turns off the built-in copy-on-write (CoW) feature of btrfs due to slower performance associated with CoW.

chattr description

[edit]

The form of thechattr 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 messages

lsattr description

[edit]

The form of thelsattr 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, includingdotfiles
  • -d lists directories like other files, rather than listing their contents

Attributes

[edit]

Some attributes include:

File attributes on a Linux file system according to thechattr(1) Linux man page
Attributelsattr flagchattr optionSemantics and rationale
Noatime updatesA+A to set
-A to clear
  • When a file with theA attribute set is accessed, itsatime record is not modified.
  • This avoids a certain amount of disk I/O operations.
Append onlya+a to set
-a to clear[note 1]
  • A file with thea attribute set can only be open in append mode for writing.
Compressedc+c to set
-c to clear[note 2]
  • A file with thec 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 theC 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 updatesD+D to set
-D to clear
  • When a directory with theD attribute set is modified, the changes are written synchronously on the disk
  • This is equivalent to thedirsyncmount option, applied to a subset of the files.
No dumpd+d to set
-d to clear
  • A file with thed attribute set is not candidate for backup when thedump program is run.
Compression errorE(unavailable)
  • TheE attribute is used by the experimental compression patches to indicate that a compressed file has a compression error.
Extent formate(unavailable)
  • Thee attribute indicates that the file is usingextents for mapping the blocks on disk.
Huge fileh(unavailable)
  • Theh 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 directoryI(unavailable)
  • TheI attribute is used by thehtree program code to indicate that a directory is being indexed using hashed trees.
Immutablei+i to set
-i to clear[note 1]
  • A file with thei 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 journalingj+j to set
-j to clear[note 4]
  • A file with thej attribute has all of its data written to theext3 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 alreadyjournaled, so this attribute has no effect.
Secure deletions+s to set
-s to clear[note 2][note 5]
Synchronous updatesS+S to set
-S to clear
  • When a file with theS 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 thesyncmount option, applied to a subset of the files.
Top of directory hierarchyT+T to set
-T to clear
  • A directory with theT attribute will be deemed to be the top of directory hierarchies for the purposes of theOrlov block allocator.
  • This is a hint to the block allocator used byext3 andext4 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 theT 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-mergingt+t to set
-t to clear
  • For those filesystems that supporttail-merging, a file with thet attribute will not have a partial block fragment at the end of the file merged with other files.
  • This is necessary for applications such asLILO, which reads the filesystem directly and doesn't understand tail-merged files.
Undeletableu+u to set
-u to clear[note 2]
  • When a file with theu attribute set is deleted, its contents are saved.
  • This allows the user to ask for itsundeletion.
Compression raw accessX(unavailable)
  • TheX attribute is used by the experimental compression patches to indicate that a raw contents of a compressed file can be accessed directly.
Compressed dirty fileZ(unavailable)
  • TheZ attribute is used by the experimental compression patches to indicate a compressed file is "dirty".
Version / generation number-v-vversion
  • File's version/generation number.

Notes

[edit]
  1. ^abOnly the superuser or a process possessing theCAP_LINUX_IMMUTABLE capability can set or clear these attributes.
  2. ^abcThese attributes are not honored by theext2 andext3 filesystems as implemented in the current mainline Linux kernels.
  3. ^These attributes only make sense for Copy-on-Write file-systems such asbtrfs.
  4. ^Only the superuser or a process possessing theCAP_SYS_RESOURCE capability can set or clear this attribute.
  5. ^This attribute is not honored by theext4 filesystem as implemented in the current mainline Linux kernelsas reported in Bug #17872.

In BSD-like systems (chflags)

[edit]

File system support

[edit]

Thechflags command is not specific to particular file systems.UFS on BSD systems, andAPFS,HFS+,SMB,AFP, andFAT on macOS support at least some flags.

chflags description

[edit]

The form of thechflags 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.

Displaying

[edit]

BSD-like systems, in general, have no default user-level command specifically meant to display the flags of a file. Thels command will do with either the-lo, or the-lO, depending on the system, flags passed.

Attributes

[edit]

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
Attributels flagchflags flagOwner-settableOS supportSemantics and rationale
Archivedarcharch,archivedNoAllFile is archived
OpaqueopaqueopaqueYesAllDirectory is opaque when viewed through a union mount
No dumpnodumpnodumpYesAllFile cannot be dumped
System append-onlysappndsappnd,sappendNoAllExisting data in the file can't be overwritten and the file cannot be truncated
User append-onlyuappnduappnd,uappendYesAllExisting data in the file can't be overwritten and the file cannot be truncated
System immutableschgschg,schange,simmutableNoAllFile cannot be changed, renamed, moved, or removed
User immutableuchguchg,uchange,uimmutableYesAllFile cannot be changed, renamed, moved, or removed
System no-unlinksunlnksunlnk, sunlinkNoFreeBSD, DragonFly BSD, macOSFile cannot be removed, renamed or mounted on; on macOS this flag needs to be set or cleared fromsingle user mode
User no-unlinkuunlnkuunlnk, uunlinkYesFreeBSD, DragonFly BSDFile cannot be removed, renamed or mounted on
HiddenhiddenhiddenYesmacOSFile is hidden by default in the GUI (but not inls)
Hiddenhiddenhidden, uhiddenYesFreeBSDFile might be hidden by default in some GUI desktops (but not inls)
TrackedtrackedtrackedYesmacOSFile modifications and deletions are tracked
RestrictedrestrictedrestrictedNomacOSFile is protected bySystem Integrity Protection; accompanied by theextended attributecom.apple.rootless; flag needs to be set or cleared from Recovery Mode
CompressedcompressedNomacOSFile isHFS-compressed (read-only flag); not available onAPFS-formatted volumes
Data VaultNomacOSHidden privacy flag sincemacOS Mojave set by the core system to prohibit any access without special entitlements
Offlineofflineoffline, uofflineYesFreeBSDFile is offline
SnapshotsnapshotNoFreeBSD, NetBSDFile is a snapshot file (read-only flag)
Sparsesparsesparse, usparseYesFreeBSDWrites of all zeroes may be written as "holes"
Must be archiveduarchuarch, uarchiveYesFreeBSDFile must be archived

See also

[edit]
  • 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

[edit]
  1. ^chmod(1) – illumos andOpenSolaris User Commands ReferenceManual from latest Sun basedOpenSolaris
  2. ^ls(1) – illumos andOpenSolaris User Commands ReferenceManual from latest Sun basedOpenSolaris
  3. ^chflags(1) – OpenBSD General CommandsManual

References

[edit]
File system
Processes
User environment
Text processing
Shell builtins
Searching
Documentation
Software development
Miscellaneous
Retrieved from "https://en.wikipedia.org/w/index.php?title=Chattr&oldid=1272999217"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2025 Movatter.jp