1、列出當前系統上所有已經登錄的用戶的用戶名,注意:同一個用戶登錄多次,則只顯示一次即可。
who | cut -d" " -f1 | sort -u
who | cut -d" " -f1 | uniq
2、取出最后登錄到當前系統的用戶的相關信息。
who | tail -1
3、取出當前系統上被用戶當作其默認shell的最多的那個shell。
cut -d: -f7 < /etc/passwd | uniq -c | sort -nr | head -1 | grep -Eo "\/.*"
4、將/etc/passwd中的第三個字段數值最大的后10個用戶的信息全部改為大寫后保存至/tmp/maxusers.txt文件中。
sort -k3nr -t: </etc/passwd | head -11 | tail -10 | tr [a-z] [A-Z] >> /tmp/maxusers.txt
5、取出當前主機的IP地址,提示:對ifconfig命令的結果進行切分。
ifconfig | cut -d: -f2| grep -Eo "
((2[0-4][0-9])|(25[0-5])|([0-1]?[0-9]?[0-9]))
\.((2[0-4][0-9])|(25[1-5])|([0-1]?[0-9]?[0-9]))
\.((2[0-4][0-9])|(25[0-5])|([0-1]?[0-9]?[0-9]))
\.((2[0-4][0-9])|(25[0-5])|([0-1]?[0-9]?[0-9]))"
6、列出/etc目錄下所有以.conf結尾的文件的文件名,并將其名字轉換為大寫后保存至/tmp/etc.conf文件中。
ls /etc/*.conf | tr [a-z] [A-Z] >> /tmp/etc.conf
7、顯示/var目錄下一級子目錄或文件的總個數。
ls -al /var | wc -l
8、取出/etc/group文件中第三個字段數值最小的10個組的名字。
sort -k3n -t: </etc/group | head | cut -d: -f1
9、將/etc/fstab和/etc/issue文件的內容合并為同一個內容后保存至/tmp/etc.test文件中。文件合并
cat /etc/fstab /etc/issue >> /tmp/etc.test
10、請總結描述用戶和組管理類命令的使用方法并完成以下練習:
(1)、創建組distro,其GID為2016;
groupadd -g 2016 distro
(2)、創建用戶mandriva, 其ID號為1005;基本組為distro;
useradd -u 1005 –g 2016 mandriva
(3)、創建用戶mageia,其ID號為1100,家目錄為/home/linux;
mkdir /home/linux
useradd -u 1100 -d /home/linux/ magei
(4)、給用戶mageia添加密碼,密碼為mageedu;
passwd mageia
(5)、刪除mandriva,但保留其家目錄;
userdel mandriva
(6)、創建用戶slackware,其ID號為2002,基本組為distro,附加組peguin;
useradd -u 2002 -g 2016 -G peguin slackware
(7)、修改slackware的默認shell為/bin/tcsh;
usermod -s /bin/tcsh slackware
(8)、為用戶slackware新增附加組admins;
usermod -G admins slackware
(9)、為slackware添加密碼,且要求密碼最短使用期限為3天,最長為180天,警告為3天;
passwd -n 3 -w 3 -x 180 slackware
(10)、添加用戶openstack,其ID號為3003, 基本組為clouds,附加組為peguin和nova;
useradd -u 3003 -g 5006 -G peguin openstack
usermod -aG nova openstack
(11)、添加系統用戶mysql,要求其shell為/sbin/nologin;
useradd -r -s /sbin/nologin mysql
(12)、使用echo命令,非交互式為openstack添加密碼。
echo "test"|passwd openstack –stdin
原創文章,作者:haoyp,如若轉載,請注明出處:http://www.www58058.com/60098
有的答案作的很有自己的想法,不錯,請繼續保持