1.列出當前系統上所有已經登錄的用戶的用戶名 注意:同一個用戶登錄多次,則只顯示一次即可
[root@02 ~]# who | cut -d' ' -f1 | uniq -c |
2.取出最後登錄到當前系統的用戶的相關信息
[root@02 ~]# id $(last | head -1 | cut -d ' ' -f 1) uid=0(root) gid=0(root) groups=0(root) |
3.取出當前系統上被用戶當作其默認shell的最多的那個shell
[root@02 ~]# cat /etc/passwd | cut -d: -f7 | sort | uniq -c | sort -n -t' ' -k2 | tail -1 | grep -o -E '/.*$' /sbin/nologin |
4.將/etc/passwd中的第三個字段數值最大的後10個用戶的信息全部改爲大寫後保存至/tmp/maxusers.txt文件中
5.取出當前主機的IP地址,提示:對ifconfig命令的結果進行切分
[root@02 ~]# ifconfig | grep "inet addr" | cut -d: -f2 | cut -d' ' -f1 | grep -v '127' 192.168.1.24 |
6.列出/etc/目錄下所有以.conf結尾的文件的文件名,並將其名字轉換爲大寫後保存至/tmp/etc.conf文件中
[root@02 ~]# find /etc/ -name “*.conf” -type f | grep -o -E “[^/]+$” | cut -d ‘.’ -f 1 | tr ‘a-z’ ‘A-Z’ > /tmp/etc.conf |
7.顯示/var/目錄下一級子目錄或文件的總個數
[root@02 ~]# ls -lh /var/ | wc -l |
8.取出/etc/group文件中第三個字段數值最小的10個組的名字
[root@02 ~]#sort -n -t : -k 3 -r /etc/group | tail -n 10 | cut -d : -f 1 |
9.將/etc/fstab和/etc/issue文件的內容合併爲同一個內容後保存至/tmp/etc.test文件中
[root@02 ~]# cat /etc/fstab /etc/issue > /tmp/etc.test |
10.請總結描述用戶和組管理類命令的使用方法並完成以下練習
創建組distro,其GID爲2016
創建用戶mandriva,其ID號爲1005,基本組爲distro
創建用戶mageia,其ID號爲1100,家目錄爲/home/linux
給用戶mageia添加密碼,密碼爲mageedu
刪除mandriva,但保留其家目錄
創建用戶slackware,其ID號爲2002,基本組爲distro,附加組peguin
修改slackware的默認shell爲/bin/tcsh
爲用戶slackware新增附加組admins
[root@02 ~]# groupadd -g 2016 distro [root@02 ~]# useradd -u 1005 -g distro mandriva [root@02 ~]# useradd -u 1100 -d /home/linux mageia [root@02 linux]# echo 'mageedu' | passwd --stdin mageia [root@02 home]# userdel mandriva [root@02 home]# useradd -u 2002 -g distro -G peguin slackware [root@02 home]# usermod -s /bin/tcsh slackware [root@02 home]# usermod -a -G admins slackware |