what does the "a" in chattr +ia do?
6,566
The letters `acdeijstuADST' select the new attributes for the files: append only (a), compressed (c), no dump (d), extent format (e), immutable (i), data journalling (j), secure deletion (s), no tail-merg‐ ing (t), undeletable (u), no atime updates (A), synchronous directory updates (D), synchronous updates (S), and top of directory hierarchy (T).
from the manpage for
chattr
Files with this flag will fail to be opened for writing. This also blocks certain potentially destructive system calls such as truncate()
or unlink()
.
$ touch foo
$ chattr +a foo
$ python
> file("foo", "w") #attempt to open for writing
[Errno 1] Operation not permitted: 'foo'
> quit()
$ truncate foo --size 0
truncate: cannot open `foo' for writing: Operation not permitted
$ echo "Appending works fine." >> foo
$ cat foo
Appending works fine.
$ rm foo
rm: cannot remove `foo': Operation not permitted
$ chattr -a foo
$ rm foo
This option is designed for log files.
Related videos on Youtube
Author by
xenoterracide
Former Linux System Administrator, now full time Java Software Engineer.
Updated on September 17, 2022Comments
-
xenoterracide almost 2 years
what does the
a
inchattr +ia <filename>
do? and why would you add thea
in combination with thei
? note: I know thei
is for immutable -
xenoterracide over 13 yearsbut why would you do immutable and append only? immutable kind of prevents any writing... (we do this at work when locking sites for TOS violations and I don't understand why the a)
-
Gilles 'SO- stop being evil' over 13 years@xenoterracide: I don't see much point. It could be belt and braces, in case someone removes the
i
(but someone who wants to and knows how do remove the immutable attribute would know about the append-only attribute anyway). -
msw over 13 years"belt and braces" in English means "belt and suspenders" in American for our international readers.