chattr +ia 中的“a”有什么作用?

xen*_*ide 3 linux filesystems permissions xattr

什么是achattr +ia <filename>做什么?为什么要a在组合中添加i注意:我知道i是不可变的

bad*_*adp 5

  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).
Run Code Online (Sandbox Code Playgroud)

联机帮助页chattr

带有此标志的文件将无法打开写入。这也会阻止某些具有潜在破坏性的系统调用,例如truncate()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
Run Code Online (Sandbox Code Playgroud)

此选项专为日志文件而设计。

  • 但为什么你会做不可变的和只追加?不可变类型阻止任何写入......(我们在锁定网站违反 TOS 时这样做,我不明白为什么 a) (2认同)