chmod只是改变文件的读写、执行权限,更底层的属性控制是由chattr来改变的,chattr控制更细腻。
[root@localhost temp]# lsattr
-------------e- ./workfile-------------e- ./2.txt
lsattr: Operation not supported While reading flags on ./4.txt
--chattr的i参数使文件不能修改与删除
[root@localhost temp]# chattr +i 2.txt
[root@localhost temp]# lsattr
-------------e- ./workfile
----i--------e- ./2.txt
lsattr: Operation not supported While reading flags on ./4.txt
--不能删除
[root@localhost temp]# rm -f 2.txt
rm: cannot remove `2.txt': Operation not permitted
--不能修改
[root@localhost temp]# echo aaa>2.txt
bash: 2.txt: Permission denied
--chattr的a属性使文件只能在末尾追加内容
[root@localhost temp]# chattr +a 2.txt
[root@localhost temp]# lsattr
-------------e- ./workfile
-----a-------e- ./2.txt
lsattr: Operation not supported While reading flags on ./4.txt
--不能覆盖更新
[root@localhost temp]# echo aaa>2.txt
bash: 2.txt: Operation not permitted
--只能追加
[root@localhost temp]# echo aaa>>2.txt
[root@localhost temp]# cat 2.txt
aaa
aaa