1、列出当前系统上的所有已经登录的用户的用户名
[root@localhost home]# who | cut -d" " -f1 | uniq root test root
2、取出最后登录到当前系统的用户相关信息
[root@localhost home]# who | tail -1 root pts/3 2017-07-16 19:38 (192.168.2.46)
3、取出当前系统上被用户当作其默认shell的最多的那个shell
[root@localhost home]# cut -d: -f7 /etc/passwd | uniq -c | sort -n | tail -1 13 /sbin/nologin
4、将/etc/passwd中的第三个字段数值最大的后10个用户的信息全部改为大写后保存至/tmp/maxusers.txt文件中
[root@localhost home]# sort -t: -k3 -n /etc/passwd | tail | tr [a-z] [A-Z] > /tmp/maxusers.txt [root@localhost home]# cat /tmp/maxusers.txt AVAHI-AUTOIPD:X:170:170:AVAHI IPV4LL STACK:/VAR/LIB/AVAHI-AUTOIPD:/SBIN/NOLOGIN POLKITD:X:997:995:USER FOR POLKITD:/:/SBIN/NOLOGIN SYSTEMD-NETWORK:X:998:996:SYSTEMD NETWORK MANAGEMENT:/:/SBIN/NOLOGIN SYSTEMD-BUS-PROXY:X:999:997:SYSTEMD BUS PROXY:/:/SBIN/NOLOGIN GENTOO:X:1000:1000::/HOME/GENTOO:/BIN/BASH MAGEIA:X:1100:1100::/HOME/LINUX:/BIN/BASH SLACKWARE:X:2002:2016::/HOME/SLACKWARE:/BIN/TCSH TEST:X:4001:1000:SHIJL,HS,110,119:/VAR/TMP/GENTOO:/BIN/BASH FEDORS:X:4002:4002:FEDORA CORE:/HOME/FEDORS:/BIN/TCSH TEST2:X:4003:4003::/HOME/TEST2:/BIN/BASH
5、取出当前主机的IP地址,提示:对ifconfig命令的结果进行切分
[root@localhost home]# ifconfig | grep inet inet 192.168.2.250 netmask 255.255.255.0 broadcast 192.168.2.255 inet6 fe80::20c:29ff:fe73:6f14 prefixlen 64 scopeid 0x20<link> inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host>
6、列出/etc目录下所有以.conf结尾的文件的文件名,并将其名字转换为大写后保存至/tmp/etc.conf文件中
[root@localhost home]# find /etc/ -name "*.conf" | tr [a-z] [A-Z] > /tmp/etc.conf [root@localhost home]# cat /tmp/etc.conf /ETC/RESOLV.CONF /ETC/PKI/CA-TRUST/CA-LEGACY.CONF /ETC/YUM/PLUGINCONF.D/FASTESTMIRROR.CONF /ETC/YUM/PLUGINCONF.D/LANGPACKS.CONF /ETC/YUM/PROTECTED.D/SYSTEMD.CONF /ETC/YUM/VERSION-GROUPS.CONF /ETC/YUM/YUM-CRON-HOURLY.CONF /ETC/YUM/YUM-CRON.CONF
#由于文件大多,只是截图一部分;
7、显示/var目录下一级子目录或文件的总个数
[root@localhost ~]# ls /var/ | wc -w 20
8、取出/etc/group文件中第三个字段数值最小的10个组的名字
[root@localhost ~]# sort -t: -k3 -n /etc/group | head | cut -d: -f1 root bin daemon sys adm tty disk lp mem kmem
9、将/etc/fstab和/etc/issue文件的内容合并为同一个内容后保存至/tmp/etc.test文件中
[root@localhost ~]# cat /etc/{fstab,issue} > /tmp/etc.test [root@localhost ~]# cat /tmp/etc.test # # /etc/fstab # Created by anaconda on Thu Jul 6 13:10:02 2017 # # 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-root / xfs defaults 0 0 UUID=67f1323c-af86-45f5-8538-88e92b7787e8 /boot xfs defaults 0 0 /dev/mapper/centos-home /home xfs defaults 0 0 /dev/mapper/centos-swap swap swap defaults 0 0 \S Kernel \r on an \m
10、请总结描述用户和组管理类命令的使用方法并完成以下练习:
useradd,usermod,userdel,passwd,groupadd,groupmod,groupdel,gpasswd,chfn, chsh,finger,id,su;
(1)创建组distro,其GID为2016;
~]#groupadd -g 2016 distro
(2)创建用户mandriva,其ID号为1005;基本组为distro;
~]#useradd -u 1005 -g distro mandriva
(3)创建用户mageia,其ID号为1100,家目录为/home/linux;
~]#useradd -u 1100 -d /home/linux mageia
(4)给用户mageia添加密码,密为tangkai;
~]#echo "tangkai" | passwd --stdin mageia
(5)删除mandriva,但保留其家目录;
~]#userdel mandriva
(6)创建用户slackware,其ID号为2002,基本组为distro,附加组peguin;
~]#groupadd peguin ~]#useradd -u 2002 -g distro -G peguin slackware
(7)修改slackware的默认shell为/bin/tcsh;
~]#usermod -s /bin/tcsh slackware
(8)为用户slackware新增附加组admins;
~]#groupadd admins ~]#usermod -a -G admins slackware
原创文章,作者:N27_shijinlong,如若转载,请注明出处:http://www.178linux.com/81340
评论列表(1条)
非常棒,再接再励。