1、列出當前系統上所有已經登錄的用戶的用戶名,注意:同一個用戶登錄多次,則只顯示一次即可。
[root@centos7 ~]#who | cut -d ” ” -f 1 | sort -u
centos
root
wang
2、取出最后登錄到當前系統的用戶的相關信息。
[root@centos7 ~]#last | head -1
centos?? tty5? ????????????????????????Sun Jul? 8 13:17?? still logged in
3、取出當前系統上被用戶當作其默認shell的最多的那個shell。
[root@centos7 ~]#cat /etc/passwd | cut -d “:” -f 7 | uniq -c | sort -n | tail -1
32 /sbin/nologin
4、將/etc/passwd中的第三個字段數值最大的后10個用戶的信息全部改為大寫后保存至/tmp/maxusers.txt文件中。
[root@centos7 ~]#cat /etc/passwd | sort -t “:” -k 3 -n | tail -10 | tr ‘a-z’ ‘A-Z’ > /tmp/maxusers.txt
[root@centos7 ~]#cat /tmp/maxusers.txt
COLORD:X:997:995:USER FOR COLORD:/VAR/LIB/COLORD:/SBIN/NOLOGIN
LIBSTORAGEMGMT:X:998:996:DAEMON ACCOUNT FOR LIBSTORAGEMGMT:/VAR/RUN/LSM:/SBIN/NOLOGIN
POLKITD:X:999:998:USER FOR POLKITD:/:/SBIN/NOLOGIN
WANG:X:1000:1000:WANG:/HOME/WANG:/BIN/BASH
GENTOO:X:4001:4001::/HOME/GENTOO:/BIN/BASH
FEDORA:X:4002:4002:FEDORA CORE:/HOME/FEDORA:/BIN/TCSH
MARIADB:X:4003:5002::/HOME/MARIADB:/SBIN/NOLOGIN
USER2:X:4004:4004::/HOME/USER2:/BIN/BASH
CENTOS:X:4005:4005::/HOME/CENTOS:/BIN/BASH
NFSNOBODY:X:65534:65534:ANONYMOUS NFS USER:/VAR/LIB/NFS:/SBIN/NOLOGIN
5、取出當前主機的IP地址,提示:對ifconfig命令的結果進行切分。
[root@centos7 ~]#ifconfig ens33 | grep “\<inet\>” | cut -b 14-27
192.168.31.129
6、列出/etc目錄下所有以.conf結尾的文件的文件名,并將其名字轉換為大寫后保存至/tmp/etc.conf文件中。
[root@centos7 ~]#ls /etc/*.conf | tr ‘a-z’ ‘A-Z’>/tmp/etc.conf
7、顯示/var目錄下一級子目錄或文件的總個數。
[root@centos7 ~]#ll -d /var/* | wc -l
22
8、取出/etc/group文件中第三個字段數值最小的10個組的名字。
[root@centos7 ~]#cat /etc/group | sort -t “:” -k 3 -n | head -3 | cut -d”:” -f 1
root
bin
daemon
9、將/etc/fstab和/etc/issue文件的內容合并為同一個內容后保存至/tmp/etc.test文件中。
[root@centos7 ~]#cat /etc/fstab /etc/issue > /tmp/etc.test
10、請總結描述用戶和組管理類命令的使用方法并完成以下練習:
(1)、創建組distro,其GID為2016;
[root@centos7 ~]#groupadd distro -g 2016
[root@centos7 ~]#tail -1 /etc/group
distro:x:2016:
(2)、創建用戶mandriva, 其ID號為1005;基本組為distro;
[root@centos7 ~]#useradd mandriva -u 1005 -g distro
[root@centos7 ~]#id mandriva
uid=1005(mandriva) gid=2016(distro) groups=2016(distro)
(3)、創建用戶mageia,其ID號為1100,家目錄為/home/linux;
[root@centos7 ~]#useradd mageia -u 1100 -d /home/linux
[root@centos7 ~]#tail -1 /etc/passwd
mageia:x:1100:1100::/home/linux:/bin/bash
(4)、給用戶mageia添加密碼,密碼為mageedu;
[root@centos7 ~]#echo “mageedu” | passwd –stdin mageia
Changing password for user mageia.
passwd: all authentication tokens updated successfully.
(5)、刪除mandriva,但保留其家目錄;
[root@centos7 ~]#userdel mandriva
[root@centos7 ~]#ls /home/
centos? fedora? gentoo? linux? mandriva? user2? wang
(6)、創建用戶slackware,其ID號為2002,基本組為distro,附加組peguin;
[root@centos7 ~]#useradd slackware -u 2002 -g distro -G peguin
[root@centos7 ~]#id slackware
uid=2002(slackware) gid=2016(distro) groups=2016(distro),5001(peguin)
(7)、修改slackware的默認shell為/bin/tcsh;
[root@centos7 ~]#usermod slackware -s /bin/tcsh
[root@centos7 ~]#tail -1 /etc/passwd
slackware:x:2002:2016::/home/slackware:/bin/tcsh
(8)、為用戶slackware新增附加組admins;
[root@centos7 ~]#usermod slackware -G admins
本文來自投稿,不代表Linux運維部落立場,如若轉載,請注明出處:http://www.www58058.com/102473