实验题目
1.修改主机的用户名为Workstation
2.在/目录下查找以s结尾的文件(不区分大小写)并放到1.html中
3.创建协作目录 /home/managers,修改该目录所属组权限为sgid
4.将文件/etc/fstab复制到/tmp/fstab,配置 /tmp/fstab的权限满足如下条件
(1)文件/tmp/fstab应不能被任何人执行
(2)user01用户能够读取和写入/tmp/fstab
(3)user02用户无法读取和写入/tmp/fstab
(4)所有用户(当前或者未来)能够更改/tmp/fstab
使用命令
修改主机名(临时)
hostname zzzzzz #临时修改主机名为:zzzzzz
//T1
//设置用户主机名 (临时设置-方法1)
[root@localhost ~]# hostname Workstation
//查看用户主机名(验证步骤)
[root@localhost ~]# hostname
Workstation
//永久设置(方法2)
[root@localhost ~]# sysctl kernel.hostname=Workstation
//T2
//创建1.html
[root@localhost ~]# touch 1.html
//拷贝调用
[root@localhost ~]# find / -iname "*s" >1.html
//T3
//创建协作目录
[root@localhost home]# mkdir /home/managers
[root@localhost home]# ll
total 4
drwxr-xrw-. 2 root root 6 Mar 31 11:48 managers
//修改权限 sgid(方法1)
[root@localhost home]# chmod g+s /home/managers
[root@localhost home]# ll
total 4
drwxr-srw-. 2 root root 6 Mar 31 11:48 managers
//数值法设置权限 sgid (方法2)
//缺点是不会完全按照数值设置,建议还是用符号法比较保险
[root@localhost home]# chmod 726 /home/managers
[root@localhost home]# ll
total 4
drwx-wSrw-. 2 root root 6 Mar 31 11:48 managers
//T4
//将文件/etc/fstab复制到/tmp/fstab
[root@localhost ~]# cp /etc/fstab /tmp/fstab
[root@localhost ~]# cd /tmp
//文件fstab权限有:可读可写
[root@localhost tmp]# ll
total 17616
-rw-r--r--. 1 root root 579 Mar 31 14:58 fstab
//查看权限
[root@localhost tmp]# getfacl fstab
# file: fstab
# owner: root
# group: root
user::rw-
group::r--
other::r--
//增加user01用户的读r和写入w权限
[root@localhost tmp]# setfacl -m u:user01:rw- fstab
[root@localhost tmp]# getfacl fstab
# file: fstab
# owner: root
# group: root
user::rw-
user:user01:rw-
group::r--
mask::rw-
other::r--
//使user02用户不具有所有权限
[root@localhost tmp]# setfacl -m u:user02:--- fstab
[root@localhost tmp]# getfacl fstab
# file: fstab
# owner: root
# group: root
user::rw-
user:user01:rw-
user:user02:---
group::r--
mask::rw-
other::r--
//使所有用户(当前/未来可以更改/tmp/fstab)具有x权限
[root@localhost tmp]# chmod a+x fstab
[root@localhost tmp]# getfacl fstab
# file: fstab
# owner: root
# group: root
user::rwx
user:user01:rw-
user:user02:---
group::r--
mask::rwx
other::r-x
一些错误
事实上证明我想复杂了
使用语句:[root@localhost ~]# find / -iname "*s" -exec cp {} /1.html \;错误
not specified; omitting directory
使用语句:[root@localhost ~]# cat / | grep -i "*s">1.html 错误
使用[root@localhost ~]# ls /|grep -i "*s" >1.html 错误:
不写入
在linux下拷贝的时候有时候会出现cp:omitting directory的错误 ,例如 cp:omitting directory “bbs” 说明bbs目录下面还有目录,不能直接拷贝
解决办法:递归拷贝 命令:cp -r bbs ../backup/bbs 解释:-r 这个options是递归的意思
举一反三:删除的时候也可能出现这种下面有文件不能删除的问题 也用-r 级联删除
chmod赋予权限的时候想级联也可以用-R 注意是大写的R
//T3建目录不小心建错了 用rmdir删除
[root@localhost ~]# mkdir /home/manage
[root@localhost ~]# cd /home
[root@localhost home]# ll
total 4
drwxr-xrw-. 2 root root 6 Mar 31 11:43 manage
drwx------. 15 mika mika 4096 Feb 24 14:53 mika
drwx------. 4 qq qq 128 Mar 22 11:35 qq
drwx------. 4 student1 student1 126 Mar 17 10:59 student1
drwx------. 3 student2 student2 78 Mar 29 11:22 student2
drwx------. 3 student6 student6 78 Mar 22 11:08 student6
drwx------. 4 teacher3 teacher3 113 Mar 15 14:39 teacher3
drwx------. 3 teacher4 teacher4 78 Mar 15 14:57 teacher4
drwx------. 5 test test 114 Mar 15 10:55 test
drwx------. 3 tt tt 78 Mar 15 10:32 tt
drwx------. 3 user01 root 78 Mar 24 10:44 user01
drwx------. 3 user02 user02 78 Mar 24 10:54 user02
[root@localhost home]# chmod g+s managers
chmod: cannot access 'managers': No such file or directory
[root@localhost home]# chmod g+s /home/managers
chmod: cannot access '/home/managers': No such file or directory
[root@localhost home]# rm manage
rm: cannot remove 'manage': Is a directory
[root@localhost home]# rm -f manage
rm: cannot remove 'manage': Is a directory
[root@localhost home]# rmdir manage
T2结果验证