1、显示/etc目录下,以非字母开头,后面跟了一个字母以及其它任意长度任意字符的文件或目录
[root@bogon ~]# ls /etc/[^a-z][a-z]*
2、复制/etc目录下所有以p开头,以非数字结尾的文件或目录到/tmp/mytest1目录中。
[zhangchuangfei@bogon ~]$ mkdir /tmp/mytest1 ;cp -ar /etc/p*[^0-9$] /tmp/mytest1/ cp: cannot access ‘/etc/pki/CA/private’: Permission denied cp: cannot access ‘/etc/pki/rsyslog’: Permission denied [zhangchuangfei@bogon ~]$ ls /tmp/mytest1/ pam.d passwd- plymouth popt.d ppp printcap profile.d python passwd pki pm postfix prelink.conf.d profile protocols
3、将/etc/issue文件中的内容转换为大写后保存至/tmp/issue.out文件中
[zhangchuangfei@bogon ~]$ tr 'a-z' 'A-Z' < /etc/issue >> /tmp/issue.out [zhangchuangfei@bogon ~]$ cat /tmp/issue.out \S KERNEL \R ON AN \M
4、请总结描述用户和组管理类命令的使用方法并完成以下练习:
(1)、创建组distro,其GID为2019;
[root@bogon ~]# groupadd -g 2019 distro
(2)、创建用户mandriva, 其ID号为1005;基本组为distro;
[root@bogon ~]# useradd -u 1005 -g distro mandriva
(3)、创建用户mageia,其ID号为1100,家目录为/home/linux;
[root@bogon ~]# useradd -u 1100 -d /home/linux mageia
(4)、给用户mageia添加密码,密码为mageedu,并设置用户密码7天后过期
[root@bogon ~]# echo "mageedu"|passwd --stdin mageia Changing password for user mageia. passwd: all authentication tokens updated successfully. [root@bogon ~]# chage -M 7 mageia
(5)、删除mandriva,但保留其家目录;
[root@bogon ~]# userdel mandriva
(6)、创建用户slackware,其ID号为2002,基本组为distro,附加组peguin;
[root@bogon ~]# groupadd peguin [root@bogon ~]# useradd -u 2002 -g distro -G peguin slackware
(7)、修改slackware的默认shell为/bin/tcsh;
[root@bogon ~]# usermod -s /bin/tcsh slackware
(8)、为用户slackware新增附加组admins,并设置不可登陆
[root@bogon ~]# groupadd admins [root@bogon ~]# groupmems -a slackware -g admins [root@bogon ~]# usermod -s /sbin/nologin slackware
5、创建用户user1、user2、user3。在/data/下创建目录test
[root@bogon ~]# for i in `echo user{1..3}`;do useradd ${i};done [root@bogon ~]# mkdir -p /data/test
(1)、目录/data/test属主、属组为user1
[root@bogon ~]# chown user1:user1 /data/test [root@bogon ~]# ls -ld /data/test drwxr-xr-x. 2 user1 user1 6 Aug 9 21:01 /data/test
(2)、在目录属主、属组不变的情况下,user2对文件有读写权限
[root@bogon ~]# usermod -G user1 user2 [root@bogon ~]# chmod 775 /data/test [root@bogon ~]# su - user2 Last login: Mon Aug 9 21:05:32 CST 2021 on pts/0 [user2@bogon ~]$ cd /data/test/ [user2@bogon test]$ ls -l total 4 -rw-rw-r--. 1 user1 user1 6 Aug 9 21:05 abc.txt [user2@bogon test]$ echo "123" >> abc.txt [user2@bogon test]$ cat abc.txt user1 123
(3)、user1在/data/test目录下创建文件a1.sh, a2.sh, a3.sh, a4.sh,设置所有用户都不可删除1.sh,2.sh文件、除了user1及root之外,所有用户都不可删除a3.sh, a4.sh
[root@bogon ~]# su - user1 Last login: Mon Aug 9 21:04:46 CST 2021 on pts/0 [user1@bogon ~]$ touch /data/test/a{1..4}.sh [root@bogon ~]# chattr +i /data/test/a{1,2}.sh [root@bogon ~]# cd /data/test/ [root@bogon test]# rm a1.sh rm: remove regular empty file ‘a1.sh’? y rm: cannot remove ‘a1.sh’: Operation not permitted [root@bogon test]# rm -f a2.sh rm: cannot remove ‘a2.sh’: Operation not permitted [user1@bogon test]$ lsattr ---------------- ./abc.txt ----i----------- ./a1.sh ----i----------- ./a2.sh ---------------- ./a3.sh ---------------- ./a4.sh [user1@bogon test]$ rm a1.sh rm: remove write-protected regular empty file ‘a1.sh’? y rm: cannot remove ‘a1.sh’: Operation not permitted [user1@bogon test]$ rm -f a2.sh rm: cannot remove ‘a2.sh’: Operation not permitted [root@bogon test]# chmod o+t /data/test [root@bogon test]# ll -d /data/test/ drwxrwxr-t. 2 user1 user1 73 Aug 9 21:32 /data/test/ [user1@bogon test]$ rm a3.sh [user1@bogon test]$ ls a1.sh a2.sh a4.sh abc.txt
(4)、user3增加附加组user1,同时要求user1不能访问/data/test目录及其下所有文件
[root@bogon ~]# usermod -G user1 user3 [root@bogon ~]# setfacl -m u:user1:- /data/test/* [root@bogon ~]# chown root:root -R /data/test [root@bogon ~]# su - user1 Last login: Mon Aug 9 21:57:28 CST 2021 on pts/0 [user1@bogon ~]$ cd /data/test/ [user1@bogon test]$ ls a1.sh a2.sh a4.sh abc.txt [user1@bogon test]$ ls -l total 4 -rw-rw-r--+ 1 root root 0 Aug 9 21:32 a1.sh -rw-rw-r--+ 1 root root 0 Aug 9 21:32 a2.sh -rw-rw-r--+ 1 root root 0 Aug 9 21:32 a4.sh -rw-rw-r--+ 1 root root 18 Aug 9 21:52 abc.txt [user1@bogon test]$ cat abc.txt cat: abc.txt: Permission denied [user1@bogon test]$ echo "789" >> abc.txt -bash: abc.txt: Permission denied [user1@bogon test]$
(5)、清理/data/test目录及其下所有文件的acl权限
[root@bogon ~]# setfacl -b /data/test/*