1.顯示/etc目錄下 以非字母開頭,後面跟了一個字母以及其餘任意長度任意字符的文件或目錄 linux
[16:30:44 root@CentOS7 /etc]#ls *.txt
24a.txt 2aa.txt 33.txt 5c.txt 6b2.txt
git
[16:31:10 root@CentOS7 /etc]#ls /etc/[0-9][^0-9]*
/etc/2aa.txt /etc/5c.txt /etc/6b2.txt
shell
或centos
[16:35:02 root@CentOS7 /etc]#ls /etc/[[:digit:]][[:alpha:]]*
bash
[16:36:18 root@CentOS7 /etc]#ls /etc/[^[:alpha:]][[:alpha:]]*
ide
或ui
[16:45:26 root@CentOS7 /etc]#ls |grep ^[[:digit:]][[:alpha:]].*
2aa.txt
5c.txt
6b2.txt加密
2.複製/etc目錄下全部以P開頭,以非數字結尾的文件或目錄到/tmp/mytest1目錄中 centos7
[16:02:50 root@CentOS7 ~]#mkdir /tmp/mytest1;cp -a /etc/[Pp]*[^0-9] /tmp/mytest1spa
3.將/etc/issue文件中的內容轉換爲大寫後保存至/tmp/issue.out文件中
[18:27:15 root@CentOS7 ~]#tr 'a-z' 'A-Z' </etc/issue >/tmp/issue.out
或
[18:32:26 root@CentOS7 ~]#cat /etc/issue|tr 'a-z' 'A-Z' >/tmp/issue.out
4.請總結描述用戶和組管理類命令的使用方法並完成如下練習
4.1)建立組distro 其GID爲2019
[18:32:57 root@CentOS7 ~]#groupadd distro -g 2019
[18:42:02 root@CentOS7 /tmp]#cat /etc/group|grep ^dist.*
distro:x:2019:
4.2)建立用戶mandriva 其ID號爲1005 基本組爲distro
[18:42:11 root@CentOS7 /tmp]#useradd -u 1005 -g 2019 mandriva
[18:48:15 root@CentOS7 ~]#cat /etc/passwd|grep ^man.*
mandriva:x:1005:2019::/home/mandriva:/bin/bash
4.3)建立用戶maqeia 其ID號爲1100 家目錄爲:/home/linux 給用戶mageia添加密碼 其密碼爲mageedu 並設置其用戶密碼7天后過時
[18:53:21 root@CentOS7 ~]#useradd -u 1100 -d /home/linux maqeia
[18:55:16 root@CentOS7 /tmp]#cat /etc/passwd|grep ^maq.*
maqeia:x:1100:1100::/home/linux:/bin/bash
[18:55:45 root@CentOS7 /tmp]#echo "mageedu" |passwd --stdin maqeia
[18:58:48 root@CentOS7 /tmp]#passwd -n 7 maqeia
4.4)刪除mandriva,但保留其家目錄
[19:03:53 root@CentOS7 /tmp]#userdel mandriva
[19:09:08 root@CentOS7 /tmp]#ls /home
centos7.6 gentoo linux mandriva
4.5)建立用戶slackware 其ID號爲:2002 基本組爲:distro 附加組爲:peguin ; 修改slackware 的默認shell爲/bin/tcsh 爲用戶slackware新增附加組admins
注意:添加附加組的時候,組必須是要存在的
[19:13:51 root@CentOS7 /tmp]#groupadd peguin
[19:14:40 root@CentOS7 /tmp]#useradd -u 2002 -g distro -G peguin slackware
[19:16:37 root@CentOS7 ~]#cat /etc/passwd|grep ^sla.*
slackware:x:2002:2019::/home/slackware:/bin/bash
[19:23:14 root@CentOS7 ~]#id slackware
uid=2002(slackware) gid=2019(distro) groups=2019(distro),2020(peguin)
[19:24:24 root@CentOS7 ~]#usermod -s /bin/tcsh slackware
[19:29:07 root@CentOS7 ~]#cat /etc/passwd|grep slackware
slackware:x:2002:2019::/home/slackware:/bin/tcsh
[19:33:12 root@CentOS7 ~]#groupadd admins;usermod -a -G admins slackware (這裏的-a 是爲了不將原有的附加組覆蓋掉)
[19:33:30 root@CentOS7 ~]#id slackware
uid=2002(slackware) gid=2019(distro) groups=2019(distro),2020(peguin),2021(admins)