O'Reilly logo

Linux Pocket Guide, 2nd Edition by Daniel J. Barrett

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

chattr — stdin  stdout  - file  -- opt  --help  --version

Synopsis

chattr [options] [+ − =]attributes [files]

If you grew up with other Unix systems, you might be surprised that Linux files can have additional attributes beyond their access permissions. If a file is on an “ext” filesystem (ext2, ext3, etc.), you can set these extended attributes with the chattr (change attribute) command and list them with lsattr.

As with chmod, attributes may be added (+) or removed (-) relatively, or set absolutely (=). For example, to keep a file compressed and nondumpable, run:

$ chattr +cd myfile

Attribute

Meaning

a

Append-only: appends are permitted to this file, but it cannot otherwise be edited. Root only.

A

Accesses not timestamped: accesses to this file don’t update its access timestamp (atime).

c

Compressed: data is transparently compressed on writes and uncompressed on reads.

d

Don’t dump: tell the dump program to ignore this file when making backups (see Backups and Remote Storage).

i

Immutable: file cannot be changed or deleted (root only).

j

Journaled data (ext3 filesystems only).

s

Secure deletion: if deleted, this file’s data is overwritten with zeroes.

S

Synchronous update: changes are written to disk immediately, as if you had typed sync after saving (see Disks and Filesystems).

u

Undeletable: file cannot be deleted.

There are a few other attributes too, some of them obscure or experimental. See the manpage for details.

Useful options

-R ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required