▲就业班和全程班的小伙伴看这里:(学习老王视频的作业第5-6节)
1、显示/etc目录下,以非字母开头,后面跟了一个字母以及其它任意长度任意字符的文件或目录
[root@centos7 ~]#ll -d /etc/[^[:alpha:]][:alpha:]*
-rw-r--r-- 1 root root 0 Feb 22 20:08 /etc/2a444.log
2、复制/etc目录下所有以p开头,以非数字结尾的文件或目录到/tmp/mytest1目录中。
[root@centos7 ~]#mkdir /tmp/mytest1
[root@centos7 ~]#cp -avr /etc/p*[^0-9] /tmp/mytest1
3、将/etc/issue文件中的内容转换为大写后保存至/tmp/issue.out文件中
[root@centos7 ~]#cat /etc/issue|tr "a-z" "A-Z" >/tmp/issue.out
[root@centos7 ~]#cat /tmp/issue.out
\S
KERNEL \R ON AN \M
4、请总结描述用户和组管理类命令的使用方法并完成以下练习:
(1)、创建组distro,其GID为2019;
[root@centos7 ~]#groupadd distro -g 2019
[root@centos7 ~]#getent group distro
distro:x:2019:
(2)、创建用户mandriva, 其ID号为1005;基本组为distro;
[root@centos7 ~]#useradd mandriva -u 1005 -g distro
[root@centos7 ~]#id mandriva
uid=1005(mandriva) gid=2019(distro) groups=2019(distro)
(3)、创建用户mageia,其ID号为1100,家目录为/homenux;
[root@centos7 ~]#useradd mageia -u 1100 -d /homenux
[root@centos7 ~]#id mageia
uid=1100(mageia) gid=1100(mageia) groups=1100(mageia)
[root@centos7 ~]#ll -a /homenux
total 16
(4)、给用户mageia添加密码,密码为mageedu,并设置用户密码7天后过期
[root@centos7 ~]#getent shadow mageia
mageia:$6$TSa1n5SM$LObRg2T6VWhlLiYcWVKwm5gFURktqK5sMyMSCVsg2UHjG/wUUmfAII59HtXo4rUv2nugNNnmqz7.1NgS/scTX1:18315:0:99999:7:::
[root@centos7 ~]#echo "mageedu"|passwd -x 7 --stdin mageia
Adjusting aging data for user mageia.
passwd: Success
[root@centos7 ~]#getent shadow mageia
mageia:$6$TSa1n5SM$LObRg2T6VWhlLiYcWVKwm5gFURktqK5sMyMSCVsg2UHjG/wUUmfAII59HtXo4rUv2nugNNnmqz7.1NgS/scTX1:18315:0:7:7:::
(5)、删除mandriva,但保留其家目录;
[root@centos7 ~]#getent passwd mandriva
mandriva:x:1005:2019::/home/mandriva:/bin/bash
[root@centos7 ~]#userdel mandriva
[root@centos7 ~]#ls /home
chen chi mandriva rose rost slackware
(6)、创建用户slackware,其ID号为2002,基本组为distro,附加组peguin;
[root@centos7 ~]#useradd slackware -u 2002 -g distro -G peguin
[root@centos7 ~]#id slackware
uid=2002(slackware) gid=2019(distro) groups=2019(distro),2020(peguin)
(7)、修改slackware的默认shell为/bin/tcsh;
[root@centos7 ~]#getent passwd slackware
slackware:x:2002:2019::/home/slackware:/bin/bash
[root@centos7 ~]#usermod -s /bin/tcsh slackware
[root@centos7 ~]#getent passwd slackware
slackware:x:2002:2019::/home/slackware:/bin/tcsh
(8)、为用户slackware新增附加组admins
[root@centos7 ~]#id slackware
uid=2002(slackware) gid=2019(distro) groups=2019(distro),2020(peguin)
[root@centos7 ~]#usermod -aG admins slackware
[root@centos7 ~]#id slackware
uid=2002(slackware) gid=2019(distro) groups=2019(distro),1002(admins),2020(peguin)
或
[root@centos7 ~]#id slackware
uid=2002(slackware) gid=2019(distro) groups=2019(distro),2020(peguin)
[root@centos7 ~]#gpasswd -a slackware admins
Adding user slackware to group admins
[root@centos7 ~]#id slackware
uid=2002(slackware) gid=2019(distro) groups=2019(distro),1002(admins),2020(peguin)
或
[root@centos7 ~]#id slackware
uid=2002(slackware) gid=2019(distro) groups=2019(distro),2020(peguin)
[root@centos7 ~]#groupmems -a slackware -g admins
[root@centos7 ~]#id slackware
uid=2002(slackware) gid=2019(distro) groups=2019(distro),1002(admins),2020(peguin)