1、列出當前系統上所有已經登錄的用戶的用戶名,注意:同一個用戶登錄多次,則只顯示一次即可。
[root@localhost ~]# who | cut -d ' ' -f 1 |sort -u
l_cong
root
(unknown)
2、取出最后登錄到當前系統的用戶的相關信息。
[l_cong@localhost ~]$ who | tail -1
l_cong pts/1 2017-02-15 16:32 (192.168.188.1)
3、取出當前系統上被用戶當作其默認shell的最多的那個shell。
[root@localhost ~]# cat /etc/passwd | cut -d ":" -f 7 |uniq -c | sort -r -n | head -1
29 /sbin/nologin
注意:uniq -c :統計重復出現的次數
4、將/etc/passwd中的第三個字段數值最大的后10個用戶的信息全部改為大寫后保存至/tmp/maxusers.txt文件中。
[root@localhost ~]# cat /etc/passwd | sort -t ":" -k 3 -n | tail -10 | tr [a-z] [A-Z] >> /tmp/maxusers.txt
注意:-n是按照數字大小排序,-k是指定需要排序的欄位,-t指定欄位分隔符為冒號
5、取出當前主機的IP地址,提示:對ifconfig命令的結果進行切分。
[root@localhost ~]# ifconfig | grep inet | head -1 | awk '{print $2}'
192.168.188.66
6、列出/etc目錄下所有以.conf結尾的文件的文件名,并將其名字轉換為大寫后保存至/tmp/etc.conf文件中。
[root@localhost test]# ls /etc/*.conf | tr [a-z] [A-Z] >> /tmp/etc.conf
7、顯示/var目錄下一級子目錄或文件的總個數。
[root@localhost ~]# ls /var/ | wc -l
23
8、取出/etc/group文件中第三個字段數值最小的10個組的名字。
[root@localhost ~]# cat /etc/group | sort -t ":" -k 3 -n |head -10 |cut -d ":" -f 1
root
bin
daemon
sys
adm
tty
disk
lp
mem
kmem
9、將/etc/fstab和/etc/issue文件的內容合并為同一個內容后保存至/tmp/etc.test文件中。
[root@localhost test]# cat /etc/fstab /etc/issue >>/tmp/etc.test
10、請總結描述用戶和組管理類命令的使用方法并完成以下練習:
(1)、創建組distro,其GID為2016;
(2)、創建用戶mandriva, 其ID號為1005;基本組為distro;
(3)、創建用戶mageia,其ID號為1100,家目錄為/home/linux;
(4)、給用戶mageia添加密碼,密碼為mageedu;
(5)、刪除mandriva,但保留其家目錄;
(6)、創建用戶slackware,其ID號為2002,基本組為distro,附加組peguin;
(7)、修改slackware的默認shell為/bin/tcsh;
(8)、為用戶slackware新增附加組admins;
[root@localhost test]# groupadd -g 2016 distro
[root@localhost test]# useradd -u 1005 -g distro mandriva
[root@localhost test]# useradd -u 1100 -d /home/linux mageia
[root@localhost test]# passwd mageia
更改用戶 mageia 的密碼 。
新的 密碼:
無效的密碼: 密碼少于 8 個字符
重新輸入新的 密碼:
passwd:所有的身份驗證令牌已經成功更新。
[root@localhost test]# userdel mandriva
[root@localhost test]# groupadd peguin
[root@localhost test]# useradd -u 2002 -g distro -G peguin slackware
[root@localhost test]# usermod -s /bin/tcsh slackware
[root@localhost test]# groupadd admins
[root@localhost test]# gpasswd -a slackware admins
正在將用戶“slackware”加入到“admins”組中
原創文章,作者:N26-xiaocong,如若轉載,請注明出處:http://www.www58058.com/68793