1、显示/etc目录下,以非字母开头,后面跟了一个字母以及其它任意长度任意字符的文件或目录
[root@localhost data]#ls -a /etc/ |egrep ^[^[:alpha:]][[:alpha:]].*
.java
.pwd.lock
.updated
2、复制/etc目录下所有以p开头,以非数字结尾的文件或目录到/tmp/mytest1目录中。
[root@localhost data]#mkdir /tmp/mytest1
[root@localhost data]#cp -a /etc/p*[a-z] /tmp/mytest1/
[root@localhost data]#ls -a /tmp/mytest1
. passwd pki pnm2ppa.conf ppp profile pulse
.. pbm2ppa.conf plymouth popt.d prelink.conf.d profile.d purple
pam.d pinforc pm postfix printcap protocols python
[root@localhost ~]#cat /etc/issue S Kernel on an m [root@localhost ~]#cat /etc/issue|tr -s [[:lower:]] [[:upper:]] >/tmp/issue.out [root@localhost ~]#cat /tmp/issue.out S KERNEL R ON AN M
4、请总结描述用户和组管理类命令的使用方法并完成以下练习:
(1)、创建组distro,其GID为2019;
创建组用户groupadd -g表示指定GID
[root@localhost ~]#groupadd –g 2019 distro
(2)、创建用户mandriva, 其ID号为1005;基本组为distro;
首先创建一个组distro,然后创建用户为其指定UID和基本组
[root@localhost ~]#groupadd distro;useradd -u 1005 -g distro mandriva [root@localhost ~]#id mandriva uid=1005(mandriva) gid=2019(distro) groups=2019(distro) [root@localhost ~]#getent passwd|grep mandriva mandriva:x:1005:2019::/home/mandriva:/bin/bash
(3)、创建用户mageia,其ID号为1100,家目录为/home/linux;
[root@localhost ~]#useradd -u 1100 -d /home/linux mageia
[root@localhost ~]#id mageia uid=1100(mageia) gid=1100(mageia) groups=1100(mageia) [root@localhost ~]#cat /etc/passwd |grep mageia mageia:x:1100:1100::/home/linux:/bin/bash
(4)、给用户mageia添加密码,密码为mageedu,并设置用户密码7天后过期
[root@localhost ~]#echo mageedu |passwd --stdin mageia Changing password for user mageia. passwd: all authentication tokens updated successfully.
[root@localhost ~]#date +"%F"
2019-11-14
[root@localhost ~]#usermod -e `date -d 1weeks +%F` mageia
[root@localhost ~]#getent shadow mageia
mageia:$6$RK2orLDx$LIR17eBFYOKkDyn6d7bxsUSpUPYMjfFZSH5fAVN282XXpXIon3WpPRMN6tHSDdKMEh/Weom7rjRTtOmQcZjnn0:18214:0:99999:7::18221:
(5)、删除mandriva,但保留其家目录;
[root@localhost ~]#id mandriva uid=1005(mandriva) gid=2019(distro) groups=2019(distro) [root@localhost ~]#userdel mandriva [root@localhost ~]#ls /home/ git linux mandriva mysql nginx varnish wang
(6)、创建用户slackware,其ID号为2002,基本组为distro,附加组peguin;
[root@localhost ~]#groupadd peguin [root@localhost ~]#useradd -u 2002 -g distro -G peguin slackware [root@localhost ~]#id slackware uid=2002(slackware) gid=2019(distro) groups=2019(distro),2020(peguin)
(7)、修改slackware的默认shell为/bin/tcsh;
[root@localhost ~]#getent passwd slackware slackware:x:2002:2019::/home/slackware:/bin/bash [root@localhost ~]#usermod -s /bin/tcsh slackware [root@localhost ~]#getent passwd slackware slackware:x:2002:2019::/home/slackware:/bin/tcsh
(8)、为用户slackware新增附加组admins;
[root@localhost ~]#groupadd admins [root@localhost ~]#groupmems -a slackware -g admins [root@localhost ~]#id slackware uid=2002(slackware) gid=2019(distro) groups=2019(distro),2020(peguin),2021(admins)