一、列出当前系统上所有已经登录的用户的用户名,注意:同一个用户登录多次,则只显示一次即可?
[root@system2 ~]# who
root :0 2016-05-18 10:54 (:0)
root pts/0 2016-09-28 23:49 (:0)
[root@system2 ~]# who | cut -d ' ' -f1 | sort -u
root
二、取出最后登录到当前系统的用户的相关信息?
[root@system2 ~]# who | tail -l
root :0 2016-05-18 10:54 (:0)
root pts/0 2016-09-28 23:49 (:0)
三、取出当前系统上被用户当作其默认shell的最多的那个shell?
[root@system2 home]# cut -d : -f7 /etc/passwd | uniq -c | sort -n | tail -1
29 /sbin/nologin
四、将/etc/passw d 中的第三个字段数值最大的后10个用户的信息全部?
改为大写后保存至/tmp/maxusers.txt文件中
[root@system2 home]# sort -t: -k3 -n /etc/passwd | tail -10 |tr "a-z" "A-Z" >/tmp/maxusers.txt
[root@system2 home]# cat /tmp/maxusers.txt
ABRT:X:173:173::/ETC/ABRT:/SBIN/NOLOGIN
GNOME-INITIAL-SETUP:X:993:991::/RUN/GNOME-INITIAL-SETUP/:/SBIN/NOLOGIN
CHRONY:X:994:993::/VAR/LIB/CHRONY:/SBIN/NOLOGIN
SASLAUTH:X:995:76:"SASLAUTHD USER":/RUN/SASLAUTHD:/SBIN/NOLOGIN
LIBSTORAGEMGMT:X:996:994:DAEMON ACCOUNT FOR LIBSTORAGEMGMT:/VAR/RUN/LSM:/SBIN/NOLOGIN
COLORD:X:997:996:USER FOR COLORD:/VAR/LIB/COLORD:/SBIN/NOLOGIN
UNBOUND:X:998:997:UNBOUND DNS RESOLVER:/ETC/UNBOUND:/SBIN/NOLOGIN
POLKITD:X:999:998:USER FOR POLKITD:/:/SBIN/NOLOGIN
STUDENT:X:1000:1000:STUDENT:/HOME/STUDENT:/BIN/BASH
NFSNOBODY:X:65534:65534:ANONYMOUS NFS USER:/VAR/LIB/NFS:/SBIN/NOLOGIN
五、取出当前主机的IP地址,提示:对ifconfig命令的结果进行切分?
[root@system2 /]# ifconfig eno16777736 | grep '<inet>' |cut -d : -f2
inet 172.16.30.30 netmask 255.255.255.0 broadcast 172.16.30.255
六、列出/etc目录下所有以.conf结尾的文件的文件名,并将其名字转换为大写后保存至/tmp/etc.conf文件中?
[root@system2 /]# ls /etc/*.conf | tr 'a-z' 'A-Z' > /tmp/etc.conf
[root@system2 /]# cat /tmp/etc.conf
/ETC/ASOUND.CONF
/ETC/BRLTTY.CONF
/ETC/CHRONY.CONF
/ETC/COLORD.CONF
/ETC/DNSMASQ.CONF
/ETC/DRACUT.CONF
/ETC/E2FSCK.CONF
/ETC/FPRINTD.CONF
/ETC/FUSE.CONF
/ETC/HBA.CONF
/ETC/HOST.CONF
/ETC/IDMAPD.CONF
/ETC/IPSEC.CONF
/ETC/KDUMP.CONF
七、显示/var目录下一级子目录或文件的总个数?
[root@system2 /]# ll -a /var/ |wc -l
27
八、取出/etc/group文件中第三个字段数值最小的10个组的名字?
[root@system2 /]# cat /etc/group | sort -t : -k3 -n -r | tail -10
kmem:x:9:
mem:x:8:
lp:x:7:
disk:x:6:
tty:x:5:
adm:x:4:
sys:x:3:
daemon:x:2:
bin:x:1:
root:x:0:
九、将/etc/fstab和/etc/issue文件的内容合并为同一个内容后保存至/tmp/etc.test文件中?
[root@system2 /]# cat /etc/fstab /etc/issue >> /tmp/etc.test
[root@system2 /]# cat /tmp/etc.test
/etc/fstab
Created by anaconda on Fri May 13 10:09:08 2016
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/rhel-root / xfs defaults 1 1
UUID=12b70854-d826-4802-aff4-4ffdc3ef9582 /boot xfs defaults 1 2
/dev/mapper/rhel-swap swap swap defaults 0 0
\S
Kernel \r on an \m
十、用户和组管理类命令的使用方法?
1、创建组distro,其GID为2016
[root@system2 ~]# groupadd -g 2016 distro
[root@system2 ~]#
2、创建用户mandriva, 其ID号为1005;基本组为distro
[root@system2 ~]# useradd -u 1005 -g distro mandriva
[root@system2 ~]# id mandriva
uid=1005(mandriva) gid=2016(distro) groups=2016(distro)
3、创建用户mageia,其ID号为1100,家目录为/home/linux
[root@system2 ~]# useradd -u 1100 -d /home/linux mageia
[root@system2 ~]# id mageia
uid=1100(mageia) gid=1100(mageia) groups=1100(mageia)
4、给用户mageia添加密码,密码为mageedu
[root@system2 home]# passwd mageia
Changing password for user mageia.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
[root@system2 home]# cat /etc/passwd |grep mageia
mageia:x:1100:1100::/home/linux:/bin/bash
5、删除mandriva,但保留其家目录
[root@system2 home]# userdel mandriva
[root@system2 home]# ls
linux mandriva student
6、创建用户slackware,其ID号为2002,基本组为distro,附加组peguin
[root@system2 home]# useradd -u 2002 -g distro -G peguin slackware
[root@system2 home]# cat /etc/passwd |grep slackware
slackware:x:2002:2016::/home/slackware:/bin/bash
[root@system2 home]# cat /etc/gshadow |grep slackware
peguin:!::slackware
7、修改slackware的默认shell为/bin/tcsh
[root@system2 home]# usermod -s /bin/tcsh slackware
[root@system2 home]# cat /etc/passwd |grep slackware
slackware:x:2002:2016::/home/slackware:/bin/tcsh
8、为用户slackware新增附加组admins
[root@system2 home]# usermod -a -G admins slackware
[root@system2 home]# cat /etc/gshadow | grep slackware
peguin:!::slackware
admins:!::slackware
9、为slackware添加密码,且要求密码最短使用期限为3天,最长为180天,警告为3天
[root@system2 home]# chage slackware
Changing the aging information for slackware
Enter the new value, or press ENTER for the default
Minimum Password Age [0]: 3
Maximum Password Age [99999]: 180
Last Password Change (YYYY-MM-DD) [2016-10-07]:
Password Expiration Warning [7]: 3
Password Inactive [-1]:
Account Expiration Date (YYYY-MM-DD) [-1]:
[root@system2 home]#
10、添加用户openstack,其ID号为3003, 基本组为clouds,附加组为peguin和nova
[root@system2 home]# useradd -u 3003 -g clouds -G peguin,nova openstack
[root@system2 home]# cat /etc/passwd |grep openstack
openstack:x:3003:1110::/home/openstack:/bin/bash
11、添加系统用户mysql,要求其shell为/sbin/nologin
[root@system2 home]# useradd -s /sbin/nologin mysq1
[root@system2 home]# cat /etc/passwd | grep mysq1
mysq1:x:3004:3004::/home/mysq1:/sbin/nologin
12、使用echo命令,非交互式为openstack添加密码
[root@system2 home]# echo "redhat" | passwd --stdin openstack
Changing password for user openstack.
passwd: all authentication tokens updated successfully.