Chattr
Encyclopedia
chattr is a command
in the Linux
operating system
that allows a user to set certain attributes
on a file residing on an ext2
-based filesystem. chflags is the analogous command on modern BSD systems, including Mac OS X
. The commands are similar to the
, OS/2
and Microsoft Windows
. Other Unix
systems have no analogous commands; Solaris supports extended file attributes, but there are no user level commands for setting or changing them, and the chatr command in HP-UX, and chattr in AIX have unrelated functions.
chattr and lsattr
utilities on Linux and the attributes they manipulate are specific to the Second Extended Filesystem family (ext2
, ext3
), and are available as part of the e2fsprogs
package. They don't work on files residing on other filesystems, e.g. ReiserFS
, FAT
.
Among other things, the command can be used to make files immutable
so that password files and certain system files cannot be erased during software upgrades.
chattr [-RVf] [-+=AacDdijsSu] [-v version] files...
The form of the chflags (OSX) command is:
chflags [-R [-H | -L | -P]] flags file ...
Command (computing)
In computing, a command is a directive to a computer program acting as an interpreter of some kind, in order to perform a specific task. Most commonly a command is a directive to some kind of command line interface, such as a shell....
in the Linux
Linux
Linux is a Unix-like computer operating system assembled under the model of free and open source software development and distribution. The defining component of any Linux system is the Linux kernel, an operating system kernel first released October 5, 1991 by Linus Torvalds...
operating system
Operating system
An operating system is a set of programs that manage computer hardware resources and provide common services for application software. The operating system is the most important type of system software in a computer system...
that allows a user to set certain attributes
File attribute
A file attribute is metadata that describes or is associated with a computer file. For example, an operating system often keeps track of the date a file was created and last modified, as well as the file's size and extension . File permissions are also kept track of...
on a file residing on an ext2
Ext2
The ext2 or second extended filesystem is a file system for the Linux kernel. It was initially designed by Rémy Card as a replacement for the extended file system ....
-based filesystem. chflags is the analogous command on modern BSD systems, including Mac OS X
Mac OS X
Mac OS X is a series of Unix-based operating systems and graphical user interfaces developed, marketed, and sold by Apple Inc. Since 2002, has been included with all new Macintosh computer systems...
. The commands are similar to the
attribAttribattrib is a command, in DOS, OS/2 and Microsoft Windows. The function of attrib is to set and remove file attributes...
command on DOSDOS
DOS, short for "Disk Operating System", is an acronym for several closely related operating systems that dominated the IBM PC compatible market between 1981 and 1995, or until about 2000 if one includes the partially DOS-based Microsoft Windows versions 95, 98, and Millennium Edition.Related...
, OS/2
OS/2
OS/2 is a computer operating system, initially created by Microsoft and IBM, then later developed by IBM exclusively. The name stands for "Operating System/2," because it was introduced as part of the same generation change release as IBM's "Personal System/2 " line of second-generation personal...
and Microsoft Windows
Microsoft Windows
Microsoft Windows is a series of operating systems produced by Microsoft.Microsoft introduced an operating environment named Windows on November 20, 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces . Microsoft Windows came to dominate the world's personal...
. Other Unix
Unix
Unix is a multitasking, multi-user computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs, including Ken Thompson, Dennis Ritchie, Brian Kernighan, Douglas McIlroy, and Joe Ossanna...
systems have no analogous commands; Solaris supports extended file attributes, but there are no user level commands for setting or changing them, and the chatr command in HP-UX, and chattr in AIX have unrelated functions.
chattr and lsattr
Lsattr
lsattr is a command-line program for listing the attributes on a Linux second extended file system . It is also a command to display attributes of devices on an AIX operating system.-Options:The form of the lsattr command :...
utilities on Linux and the attributes they manipulate are specific to the Second Extended Filesystem family (ext2
Ext2
The ext2 or second extended filesystem is a file system for the Linux kernel. It was initially designed by Rémy Card as a replacement for the extended file system ....
, ext3
Ext3
The ext3 or third extended filesystem is a journaled file system that is commonly used by the Linux kernel. It is the default file system for many popular Linux distributions, including Debian...
), and are available as part of the e2fsprogs
E2fsprogs
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....
package. They don't work on files residing on other filesystems, e.g. ReiserFS
ReiserFS
ReiserFS is a general-purpose, journaled computer file system designed and implemented by a team at Namesys led by Hans Reiser. ReiserFS is currently supported on Linux . Introduced in version 2.4.1 of the Linux kernel, it was the first journaling file system to be included in the standard kernel...
, FAT
File Allocation Table
File Allocation Table is a computer file system architecture now widely used on many computer systems and most memory cards, such as those used with digital cameras. FAT file systems are commonly found on floppy disks, flash memory cards, digital cameras, and many other portable devices because of...
.
Among other things, the command can be used to make files immutable
Immutable object
In object-oriented and functional programming, an immutable object is an object whose state cannot be modified after it is created. This is in contrast to a mutable object, which can be modified after it is created...
so that password files and certain system files cannot be erased during software upgrades.
Description
The form of the chattr command is:chattr [-RVf] [-+=AacDdijsSu] [-v version] files...
-
-R
is to recurse all subdirectories -
+i
is to set the immutable bit to prevent even root from erasing or changing the contents of a file. -
-i
is to unset the immutable bit
The form of the chflags (OSX) 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.
Attributes (chattr)
Some attributes include:- don't update atimeStat (Unix)stat is a Unix system call that returns useful data about a file inode. The semantics of stat vary between operating systems. As an example, the Unix command ls uses it to retrieve information on : time of last modification , time of last status change and time of last access .-stat functions and...
(A) - synchronousData synchronizationData synchronization is the process of establishing consistency among data from a source to a target data storage and vice versa and the continuous harmonization of the data over time. It is fundamental to a wide variety of applications, including file synchronization and mobile device...
updates (S) - synchronous directory updates (D)
- append only (a)
- compressedData compressionIn computer science and information theory, data compression, source coding or bit-rate reduction is the process of encoding information using fewer bits than the original representation would use....
(c) - no dump (d)
- immutable (i)
- data journalingJournaling file systemA journaling file system is a file system that keeps track of the changes that will be made in a journal before committing them to the main file system...
(j)
- secure deletion (s)
- top of directory hierarchy (T)
- no tail-merging (t)
- undeletable (u)
Attributes (chflags, OSX)
Some attributes include:- set the archived flag (super-user only) - arch, archived
- set the opaque flag (owner or super-user only). [Directory is opaque when viewed through a union mount] - opaque
- set the nodump flag (owner or super-user only) - nodump
- set the system append-only flag (super-user only) - sappnd, sappend
- set the system immutable flag (super-user only) - schg, schange, simmutable
- set the user append-only flag (owner or super-user only) - uappnd, uappend
- set the user immutable flag (owner or super-user only) - uchg, uchange, uimmutable
- set the hidden flag [Hide item from GUI] - hidden
See also
-
lsattr
– view file attributesLsattrlsattr is a command-line program for listing the attributes on a Linux second extended file system . It is also a command to display attributes of devices on an AIX operating system.-Options:The form of the lsattr command :... -
chown
– change file/directory ownershipChownThe chown command is used on Unix-like systems to change the owner of a file. In most implementations, it can only be executed by the superuser. Unprivileged users who wish to change the group of a file that they own may use chgrp.-Usage examples:These examples illustrate typical syntax and use... -
chmod
– change file access control attributesChmodThe chmod command is a Unix command that lets a user tell the system how much access it should permit to a file. It changes the file system modes of files and directories. The modes include permissions and special modes... -
cacls
– Microsoft Windows NT file system ACL control utilityCaclscacls and icacls are Microsoft Windows native command line utilities capable of displaying and modifying the access control lists on folders and files...