chattr用法

时间:2023-12-04 15:35:38

  

[root@localhost tmp]# umask
0022

一、chattr用法

1、创建空文件attrtest,然后删除,提示无法删除,因为有隐藏文件

[root@localhost tmp]# cd /tmp

[root@localhost tmp]# touch attrtest
[root@localhost tmp]# chattr +i attrtest
[root@localhost tmp]# rm attrtest
rm: remove regular empty file ‘attrtest’? y
rm: cannot remove ‘attrtest’: Operation not permitted

2、将文件attrtest的隐藏属性取消

[root@localhost tmp]# chattr -i attrtest
[root@localhost tmp]# ls
attrtest hsperfdata_root install ks-script-3CWMoc systemd-private-810f661cb5d247129113c096f86d7db2-cups.service-fEKfSx test2 testtouch vitest yum.log

3、删除attrtest文件,发现可以删除

[root@localhost tmp]# rm attrtest
rm: remove regular empty file ‘attrtest’? y
[root@localhost tmp]# ls
hsperfdata_root install ks-script-3CWMoc systemd-private-810f661cb5d247129113c096f86d7db2-cups.service-fEKfSx test2 testtouch vitest yum.log