码迷,mamicode.com
首页 > 系统相关 > 详细

Linux的chattr与lsattr命令介绍

时间:2017-04-10 23:50:44      阅读:909      评论:0      收藏:0      [点我收藏+]

标签:linux chattr lsattr 特殊权限

Linux的chattr与lsattr命令介绍

命令lsattr是用来查看文件、目录属性的,命令chattr是用来对其做更改的。与chmod这个命令相比,chmod只是改变文件的读写、执行权限,更底层的属性控制是由chattr来改变的。

chattr命令语法:

chattr [+-=][Asaci][文件或者目录名]

注:+表示增加,-表示减少,=表示设定。

  • A:增加该属性后,表示文件或者目录的atime将不可修改。

  • s:增加该属性后,会将数据同步写入磁盘中。

  • a:增加该属性后,表示只能追加不能删除,非root用户不能设定该属性。

  • c:增加该属性后,表示自动压缩该文件,读取时会自动解压。

  • i:增加该属性后,表示文件不能被删除、重命名、设定链接、写入以及新增数据。

注:实际工作中运用的最多的就是两个参数:i和a

举例说明:lsattr

[root@jkkhj ~]# lsattr

-------------e- ./wu.txt

-------------e- ./install.log.syslog

-------------e- ./anaconda-ks.cfg

-------------e- ./install.log

注:e表示ext4或ext3所持人的权限。

[root@jkkhj ~]# chattr +a wu.txt

[root@jkkhj ~]# lsattr

-----a-------e- ./wu.txt

-------------e- ./install.log.syslog

-------------e- ./anaconda-ks.cfg

-------------e- ./install.log

[root@jkkhj ~]# echo ‘111111‘ >> wu.txt

[root@jkkhj ~]# cat wu.txt

111111

[root@jkkhj ~]# rm -rf wu.txt

rm: cannot remove `wu.txt‘: Operation not permitted

[root@jkkhj ~]# echo ‘2222‘ > wu.txt

-bash: wu.txt: Operation not permitted

上述中:wu.txt文件增加a权限后,只可以追加,不能重定向及删除!

[root@jkkhj ~]# mkdir shiyan

[root@jkkhj ~]# lsattr

-----a-------e- ./wu.txt

-------------e- ./install.log.syslog

-------------e- ./anaconda-ks.cfg

-------------e- ./install.log

-------------e- ./shiyan

[root@jkkhj ~]# chattr +a shiyan

[root@jkkhj ~]# lsattr

-----a-------e- ./wu.txt

-------------e- ./install.log.syslog

-------------e- ./anaconda-ks.cfg

-------------e- ./install.log

-----a-------e- ./shiyan

[root@jkkhj ~]# touch shiyan/test1

[root@jkkhj ~]# cd shiyan

[root@jkkhj shiyan]# lsattr

-------------e- ./test1

[root@jkkhj shiyan]# rm -rf test1

rm: cannot remove `test1‘: Operation not permitted

上述中:shiyan目录增加a权限后,只可以在里面创建文件,而不能删除文件!

[root@jkkhj ~]# chattr -a shiyan

[root@jkkhj ~]# chattr -a wu.txt

[root@jkkhj ~]# ls

anaconda-ks.cfg  install.log  install.log.syslog  shiyan  wu.txt

[root@jkkhj ~]# lsattr

-------------e- ./wu.txt

-------------e- ./install.log.syslog

-------------e- ./anaconda-ks.cfg

-------------e- ./install.log

-------------e- ./shiyan

[root@jkkhj ~]# chattr +i wu.txt

[root@jkkhj ~]# lsattr wu.txt

----i--------e- wu.txt

[root@jkkhj ~]# echo ‘nihao‘ >> wu.txt

-bash: wu.txt: Permission denied

[root@jkkhj ~]# echo ‘nihao‘ > wu.txt

-bash: wu.txt: Permission denied

[root@jkkhj ~]# rm -rf wu.txt

rm: cannot remove `wu.txt‘: Operation not permitted

上述中:给wu.txt增加i权限之后,文件即使在root账户下也不能进行追加、重定向、删除等操作!

[root@jkkhj ~]# lsattr

----i--------e- ./wu.txt

-------------e- ./install.log.syslog

-------------e- ./anaconda-ks.cfg

-------------e- ./install.log

----i--------e- ./shiyan

[root@jkkhj ~]# touch shiyan/test2

touch: cannot touch `shiyan/test2‘: Permission denied

[root@jkkhj ~]# rm -rf shiyan

rm: cannot remove `shiyan/test1‘: Permission denied

上述中:给shiyan目录增加i权限之后,即使在root账户下也不能在shiyan目录下创建文件test1及删除shiyan这个目录等操作!

[root@jkkhj ~]# chattr -i shiyan

[root@jkkhj ~]# chattr -i wu.txt

[root@jkkhj ~]# lsattr

-------------e- ./wu.txt

-------------e- ./install.log.syslog

-------------e- ./anaconda-ks.cfg

-------------e- ./install.log

-------------e- ./shiyan

[root@jkkhj ~]# rm -rf shiyan;rm -rf wu.txt

[root@jkkhj ~]# lsattr

-------------e- ./install.log.syslog

-------------e- ./anaconda-ks.cfg

-------------e- ./install.log



本文出自 “圣骑士控魔之手” 博客,请务必保留此出处http://wutengfei.blog.51cto.com/10942117/1914695

Linux的chattr与lsattr命令介绍

标签:linux chattr lsattr 特殊权限

原文地址:http://wutengfei.blog.51cto.com/10942117/1914695

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!