Skip to content

Instantly share code, notes, and snippets.

@wangxianhe
Last active June 12, 2018 11:19
Show Gist options
  • Save wangxianhe/63103865e35ac7d30d119f8d945d60cd to your computer and use it in GitHub Desktop.
Save wangxianhe/63103865e35ac7d30d119f8d945d60cd to your computer and use it in GitHub Desktop.
chattr lsattr 命令测试

测试文件

[wxh@mu01 bu_neng_shan]$ lsattr 
-----a--------- ./test  #a属性
[wxh@mu01 bu_neng_shan]$ cat test 
aaaaa
ok
[wxh@mu01 bu_neng_shan]$ echo 3333 >> test  #追加3333
[wxh@mu01 bu_neng_shan]$ cat test 
aaaaa
ok
3333  #追加成功
[wxh@mu01 bu_neng_shan]$ 
[wxh@mu01 bu_neng_shan]$ rm test 
rm: cannot remove 'test': Operation not permitted #不能删除
[wxh@mu01 bu_neng_shan]$ vi test  #不能编辑



[wxh@mu01 bu_neng_shan]$ lsattr 
----i---------- ./test
[wxh@mu01 bu_neng_shan]$ 
[wxh@mu01 bu_neng_shan]$ rm test 
rm: remove write-protected regular file 'test'? y
rm: cannot remove 'test': Operation not permitted #不能删除
[wxh@mu01 bu_neng_shan]$ echo 3333 >> test 
-bash: test: Permission denied  #不能追加

测试目录

[wxh@mu01 bu_neng_shan]$ lsattr -d ../bu_neng_shan/
-----a--------- ../bu_neng_shan/
[wxh@mu01 bu_neng_shan]$ touch 222
[wxh@mu01 bu_neng_shan]$ ls
222  test   #能追加
[wxh@mu01 bu_neng_shan]$ lsattr 
--------------- ./test
--------------- ./222
[wxh@mu01 bu_neng_shan]$ 
[wxh@mu01 bu_neng_shan]$ 
[wxh@mu01 bu_neng_shan]$ rm test 
rm: cannot remove 'test': Operation not permitted #不能删除


[root@mu01 bu_neng_shan]# chattr -a +i ../bu_neng_shan/
[root@mu01 bu_neng_shan]# lsattr -d ../bu_neng_shan/
----i---------- ../bu_neng_shan/
[root@mu01 bu_neng_shan]# 
[wxh@mu01 bu_neng_shan]$ 
[wxh@mu01 bu_neng_shan]$ lsattr 
--------------- ./test
--------------- ./222
[wxh@mu01 bu_neng_shan]$ 
[wxh@mu01 bu_neng_shan]$ lsattr -d ../bu_neng_shan/
----i---------- ../bu_neng_shan/
[wxh@mu01 bu_neng_shan]$ touch 333
touch: cannot touch '333': Permission denied  #不能追加
[wxh@mu01 bu_neng_shan]$ rm test 
rm: cannot remove 'test': Permission denied   #不能删除
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment