第三周、用户与组

1、显示/etc目录下,以非字母开头,后面跟了一个字母以及其它任意长度任意字符的文件或目录
[root@localhost ~]#ls -a /etc/[^[:alpha:]][[:alpha:]]*
/etc/1fd
2、复制/etc目录下所有以p开头,以非数字结尾的文件或目录到/tmp/mytest1目录中。
[root@localhost ~]#mkdir /tmp/mytest1/
[root@localhost ~]#cp -av /etc/p*[^[:digit:]] /tmp/mytest1/
[root@localhost ~]#ls /tmp/mytest1/
pam.d      passwd   pbm2ppa.conf  pki       pm            popt.d   ppp             printcap  profile.d  pulse   python
papersize  passwd-  pinforc       plymouth  pnm2ppa.conf  postfix  prelink.conf.d  profile   protocols  purple

3、将/etc/issue文件中的内容转换为大写后保存至/tmp/issue.out文件中
[root@localhost ~]#cat /etc/issue |tr "a-z" "A-Z" >/tmp/issue.out
[root@localhost ~]#cat /tmp/issue.out 
\S
KERNEL \R ON AN \M

4、请总结描述用户和组管理类命令的使用方法并完成以下练习:
(1)、创建组distro,其GID为2019;
[root@localhost ~]#groupadd -g 2019 distro
[root@localhost ~]#getent group distro
distro:x:2019:
(2)、创建用户mandriva, 其ID号为1005;基本组为distro;
[root@localhost ~]#useradd -u 1005 -g 2019 mandriva
[root@localhost ~]#getent passwd 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 ~]#ls /home
linux  mandriva  wang
[root@localhost ~]#getent passwd 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.
[root@localhost ~]#chage -M 7 mageia
[root@localhost ~]#getent shadow mageia
mageia:$6$VRwwIPQe$2cssILgGEWZtAefWlf9JJmmnEr/Z5u1LBbviynld3qmljbyH7yfMuDmhOyNvYJBtuCJ3MUYIKIsHp5tCINYAv/:18381:0:7:7:::

(5)、删除mandriva,但保留其家目录;
[root@localhost ~]#userdel mageia
[root@localhost ~]#ls /home
linux  mandriva  wang
(6)、创建用户slackware,其ID号为2002,基本组为distro,附加组peguin;
[root@localhost ~]#groupadd peguin
[root@localhost ~]#getent group peguin
peguin:x:2020:
[root@localhost ~]#getent group distro
distro:x:2019:
[root@localhost ~]#useradd -u 2002 -g 2019 -G 2020 slackware
[root@localhost ~]#getent passwd slackware
slackware:x:2002:2019::/home/slackware:/bin/bash
[root@localhost ~]#groups slackware
slackware : distro peguin
[root@localhost ~]#groupmems -g peguin -l
slackware 
[root@localhost ~]#getent group peguin
peguin:x:2020:slackware
(7)、修改slackware的默认shell为/bin/tcsh;
[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 ~]#usermod -a -G admins slackware
[root@localhost ~]#groups slackware
slackware : distro peguin admins
[root@localhost ~]#getent group admins
admins:x:2021:slackware
[root@localhost ~]#getent group peguin
peguin:x:2020:slackware

猜你喜欢

转载自blog.csdn.net/wauzy/article/details/105793981