创建一个共享目录,使其他用户可以在这个目录下创建文件,但是不能删除别的用户创建的文件
创建一个共享目录,并设置权限
[root@catyuan ~]# mkdir test1
[root@catyuan ~]# chmod 777 /var/test
[root@catyuan ~]# chmod o+t /var/test ##这里也可以直接chmod 1777直接设置权限
[root@catyuan ~]# ll -d /var/test
drwxrwxrwt. 2 root root 20 Nov 20 05:25 /var/test
创建两个用户test1,test2
[root@catyuan ~]# useradd test1
[root@catyuan ~]# useradd test2
设置两个用户的密码
[root@catyuan ~]# echo "123456" | passwd --stdin test1
[root@catyuan ~]# echo "123456" | passwd --stdin test2
在共享目录下创建一个文件
[root@catyuan ~]# cd /var/test
[root@catyuan test]# touch root1
[root@catyuan test]# ll
-rw-r--r--. 1 root root 0 Nov 20 05:27 root1
切换到test1目录,对root用户创建的目录进行删除,不能删除
[root@catyuan test]# su test1
[test1@catyuan test]$ touch test11
[test1@catyuan test]$ ll
-rw-r--r--. 1 root root 0 Nov 20 05:27 root1
-rw-rw-r--. 1 test1 test1 13 Nov 20 05:25 test11
[test1@catyuan test]$ rm -rf root1
rm: cannot remove ‘root1’: Operation not permitted
切换到test2用户,对test1用户创建的文件进行删除,不能删除
[test1@catyuan test]$ su test2
[test2@catyuan test]$ ll
-rw-r--r--. 1 root root 0 Nov 20 05:27 root1
-rw-rw-r--. 1 test1 test1 13 Nov 20 05:25 test11
[test2@catyuan test]$ rm -rf test11
rm: cannot remove ‘test11’: Operation not permitted