拓展训练
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了拓展训练相关的知识,希望对你有一定的参考价值。
◆ 练习题①:● 列出当前系统上所有已经登录的用户的用户名,注意:同一个用户登录多次,则只显示一次即可。
◆ 习题解答:
● [email protected] ~]# who
● root pts/0 2018-03-21 13:35 (10.10.10.1)
● root :0 2018-03-21 17:12 (:0)
● root pts/1 2018-03-21 17:12 (:0)
◆ 练习题②:
● 取出最后登录到当前系统的用户的相关信息。
◆ 习题解答:
● [[email protected] ~]# who | tail -1
● root pts/1 2018-03-21 17:12 (:0)
◆ 练习题③:
● 取出当前系统上被用户当作其默认shell的最多的那个shell。
◆ 习题解答:
● [[email protected] ~]# cat /etc/passwd | awk -F ‘:‘ ‘{print $7}‘|sort|grep -o /sbin/nologin|head -1
● /sbin/nologin
◆ 练习题④:
● 将/etc/passwd中的第三个字段数值最大的后10个用户的信息全部改为大写后保存至/tmp/maxusers.txt文件中。
◆ 习题解答:
● [[email protected] ~]# cat /etc/passwd | awk -F ‘:‘ ‘{print $1,$3}‘ | sort -nk 2 | tail | tr [a-z] {A-Z] > /tmp/maxusers.txt
● [[email protected] ~]# cat /tmp/maxusers.txt
● GEOCLUE 994
● CHRONY 995
● SETROUBLESHOOT 996
● LIBSTORAGEMGMT 997
● COLORD 998
● POLKITD 999
● M 1000
● MCAFEE 1001
● CENTOS 1002
● NFSNOBODY 65534
◆ 练习题⑤:
● 取出当前主机的IP地址,提示:对ifconfig命令的结果进行切分。
◆ 习题解答:
● [[email protected] ~]# ifconfig | grep inet | head -1 | awk ‘{print $2}‘
● 10.10.10.152
◆ 练习题⑥:
● 列出/etc目录下所有以.conf结尾的文件的文件名,并将其名字转换为大写后保存至/tmp/etc.conf文件中。
◆ 习题解答:
● [[email protected] ~]# ls /etc/*.conf | tr [a-z] [A-Z] >> /tmp/etc.conf
● [[email protected] ~]# cat /tmp/etc.conf
● /ETC/ASOUND.CONF
● /ETC/AUTOFS.CONF
● /ETC/AUTOFS_LDAP_AUTH.CONF
● ...中间省略
● /ETC/XINETD.CONF
● /ETC/YUM.CONF
◆ 练习题⑦:
● 显示/var目录下一级子目录或文件的总个数。
◆ 习题解答:
● [[email protected] /]# ls var | wc -l
● 27
◆ 练习题⑧:
● 取出/etc/group文件中第三个字段数值最小的10个组的名字。
◆ 习题解答:
● [[email protected] /]# cat /etc/group | awk -F ‘:‘ ‘{print $1,$3}‘ | sort -nk 2 | head
● root 0
● bin 1
● daemon 2
● sys 3
● adm 4
● tty 5
● disk 6
● lp 7
● mem 8
● kmem 9
◆ 练习题⑨:
● 将/etc/fstab和/etc/issue文件的内容合并为同一个内容后保存至/tmp/etc.test文件中。
◆ 习题解答:
● [[email protected] /]# cat /etc/fstab /etc/issue > /tmp/etc.test
● [[email protected] /]# cat /tmp/etc.test
● #
● # /etc/fstab
● # Created by anaconda on Fri Feb 16 18:01:43 2018
● #
● # Accessible filesystems, by reference, are maintained under ‘/dev/disk‘
● # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
● #
● /dev/mapper/centos_magedu-root / xfs defaults 0 0
● UUID=49a2c166-afb9-421e-ac19-4e141a524dca /boot xfs defaults 0 0
● /dev/mapper/centos_magedu-home /home xfs defaults 0 0
● /dev/mapper/centos_magedu-swap swap swap defaults 0 0
● \S
● Kernel \r on an \m
◆ 练习题⑩:
● 请总结描述用户和组管理类命令的使用方法并完成以下练习:
(1)、创建组distro,其GID为2016;
◆ 习题解答:
● [[email protected] ~]# groupadd -g 2016 distro
● [[email protected] ~]# tail -1 /etc/group
● distro:x:2016:
(2)、创建用户mandriva, 其ID号为1005;基本组为distro;
◆ 习题解答:
● [[email protected] ~]# useradd mandriva -u 1005 -g distro
● [[email protected] ~]# tail -1 /etc/passwd
● mandriva:x:1005:2016::/home/mandriva:/bin/bash
(3)、创建用户mageia,其ID号为1100,家目录为/home/linux;
◆ 习题解答:
● [[email protected] home]# useradd mageia -u 1100 -d /home/linux
● [[email protected] home]# tail -1 /etc/passwd
● mageia:x:1100:1100::/home/linux:/bin/bash
(4)、给用户mageia添加密码,密码为mageedu;
◆ 习题解答:
● [[email protected] home]# echo "mageedu" | passwd --stdin mageia
● 更改用户 mageia 的密码 。
● passwd:所有的身份验证令牌已经成功更新。
(5)、删除mandriva,但保留其家目录;
◆ 习题解答:
● [[email protected] home]# tail -2 /etc/passwd | head -1
● mandriva:x:1005:2016::/home/mandriva:/bin/bash
● [[email protected] home]# userdel mandriva
● [[email protected] /]# ls -d /home/mandriva
● /home/mandriva
(6)、创建用户slackware,其ID号为2002,基本组为distro,附加组peguin;
◆ 习题解答:
● [[email protected] /]# groupadd peguin
● [[email protected] /]# useradd slackware -u 2002 -g distro -G peguin
● [[email protected] /]# tail -1 /etc/passwd
● slackware:x:2002:2016::/home/slackware:/bin/bash
● [[email protected] /]# tail -1 /etc/group
● peguin:x:2017:slackware
(7)、修改slackware的默认shell为/bin/tcsh;
◆ 习题解答:
● [[email protected] /]# usermod -s /bin/tcsh slackware
● [[email protected] /]# tail -1 /etc/passwd
● slackware:x:2002:2016::/home/slackware:/bin/tcsh
OR:
● [[email protected] /]# chsh -s /bin/tcsh slackware
● Changing shell for slackware.
● Shell changed.
● [[email protected] /]# tail -1 /etc/passwd
● slackware:x:2002:2016::/home/slackware:/bin/tcsh
(8)、为用户slackware新增附加组admins;
◆ 习题解答:
● [[email protected] /]# groupadd admins
● [[email protected] /]# usermod -G admins slackware
● [[email protected] /]# tail -1 /etc/group
● admins:x:2019:slackware
◆ 说明: 本周练习已做完,关于用户及组的建立,修改,仍需练习。
以上是关于拓展训练的主要内容,如果未能解决你的问题,请参考以下文章