linux – “chattr a”对目录的影响是什么?
作者:互联网
Linux文件属性通常记录为适用于文件.
chattr(1)联机帮助页:
A file with the ‘a’ attribute set can only be open in append mode for writing.
0x20 File can only be appended (07001).
我的问题是:
> chattr仅限于文件吗?
>它是否在新的子目录和文件上递归?
解决方法:
仅附加标志(chattr a)阻止删除目录,以及直接在该目录中创建的文件和目录:
创建测试目录和文件:
# mkdir /tmp/foo
# chattr +a /tmp/foo
该目录无法删除:
# rmdir /tmp/foo
rmdir: failed to remove ‘/tmp/foo’: Operation not permitted
现在在其中创建文件和目录:
# touch /tmp/foo/bar
# mkdir /tmp/foo/baz
让我们检查:
# lsattr -d /tmp/foo /tmp/foo/ba*
-----a-------e-- /tmp/foo
-------------e-- /tmp/foo/bar
-------------e-- /tmp/foo/baz
试着抹去东西:
# rm /tmp/foo/bar
rm: cannot remove ‘/tmp/foo/bar’: Operation not permitted
# rmdir /tmp/foo/baz
rmdir: failed to remove ‘/tmp/foo/baz’: Operation not permitted
rm -Rf /tmp/foo
rm: cannot remove ‘/tmp/foo/bar’: Operation not permitted
rm: cannot remove ‘/tmp/foo/baz’: Operation not permitted
最后,子目录和子目录中的文件不受保护:
# mkdir /tmp/foo/baz/bat
# touch /tmp/foo/baz/baff
# rm --verbose -Rf /tmp/foo/baz
removed directory: ‘/tmp/foo/baz/bat’
removed ‘/tmp/foo/baz/baff’
rm: cannot remove ‘/tmp/foo/baz’: Operation not permitted
再次注意,只有/ tmp / foo有append标志:
# lsattr -d /tmp/foo /tmp/foo/baz
-----a-------e-- /tmp/foo
-------------e-- /tmp/foo/baz
标签:linux,directory,xattr 来源: https://codeday.me/bug/20190812/1644457.html