Linux 粘着位(sticky bit)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux 粘着位(sticky bit)相关的知识,希望对你有一定的参考价值。

当设置粘着位时只有root或者owner才能删除、重命名文件。

 

示例:

用户apple默认组为fruit。

[[email protected] ~]# id apple

uid=1001(apple) gid=1001(fruit) 组=1001(fruit)

 

step1 显示water文件夹信息,文件夹当前未设置粘着位

[[email protected] /]# ls -l | grep water

drwxr-xrwx.   4 root root  4096 8月  10 21:02 water

 

step2 显示water子文件夹信息。

[[email protected] /]# ls -l water

总用量 8

drwxr-xr-x. 2 root root 4096 8月  10 21:02 mineral

drwxr-xr-x. 2 root root 4096 8月  10 21:02 pure

 

step3 删除mineral文件夹。

[[email protected] water]$ rm -r mineral/

rm:是否删除有写保护的目录 ‘mineral/‘?y

 

step4 显示water子文件夹信息。

[[email protected] water]$ ls -l

总用量 4

drwxr-xr-x. 2 root root 4096 8月  10 21:02 pure

 

step5 对water文件夹设置粘着位

[[email protected] /]# chmod o+t water

[[email protected] /]# ls -l | grep water

drwxr-xrwt.   3 root root  4096 8月  10 21:08 water

 

step6 以apple用户删除pure文件夹。

[[email protected] water]$ rm -r pure

rm:是否删除有写保护的目录 ‘pure‘?y

rm: 无法删除‘pure‘: Operation not permitted

 

step7 以root用户删除pure文件夹。

[[email protected] water]# rm -r pure/

rm:是否删除目录 ‘pure/‘?y

 

step8 显示water子文件夹信息。

[[email protected] water]# ls -l

总用量 0

 

以上是关于Linux 粘着位(sticky bit)的主要内容,如果未能解决你的问题,请参考以下文章