1、 列出當前系統上所有已經登錄的用戶的用戶名,注意:同一個用戶登錄多次,則只顯示一次即可。
[root@localhost ~]# who |cut
-d” ” -f1 | sort -u
2、 取出左后登錄到當前系統的用戶的相關信息。
[root@localhost ~]# id `last | head
-1 | cut -d’ ‘ -f1`
或者[root@localhost ~]# id
$(last | head -1 | cut -d’ ‘ -f1)
3、 取出當前系統上被用戶當作其默認shell的最多的那個shell
[root@localhost ~]# cat /etc/passwd
| cut -d”:” -f7 | uniq -c |sort -nr|head -1|cut -d”/” -f3
4、 將/etc/passwd中的第三個字段數值最大的后10個用戶的信息全部改寫為大寫后保存至/tmp/maxusers.txt文件中
[root@localhost ~]# cat /etc/passwd
| sort -t: -k3 -n | tail -10| tr ‘a-z’ ‘A-Z’ | tee /tmp/maxusers.txt
5、 取出當前主機的IP地址
ifconfig | grep -E ‘inet’ | head -1 | awk
‘{print $2}’
6、 列出/etc目錄下所有以.conf結尾的文件的文件名,并將其名字轉換為大寫后保存至/tmp/etc.conf文件中
[root@localhost ~]# ll /etc/*.conf
| awk ‘{print $9}’ | cut -d’/’ -f3 |tr ‘a-z’ ‘A-Z’ |tee /tmp/etc.conf
7、 顯示/var目錄下一級子目錄或文件的總個數
[root@localhost ~]# ls /var |wc -w
21
8、 取出/etc/group文件中第三個字段數值最小的10個組的名字
[root@localhost ~]# cat /etc/group
| sort -t: -k3 -n | head -10 |cut -d:
-f1
9、 將/etc/fstab和/etc/issue文件的內容合并為同一個內容后保存至/tmp/etc.test
[root@localhost ~]# cat /etc/fstab
/etc/issue >/tmp/etc.test
[root@localhost ~]# cat /tmp/etc.test
#
# /etc/fstab
# Created by anaconda on Mon Jul 31 09:42:26
2017
#sdf
# 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/cl-root / xfs defaults 0 0
UUID=aae3f709-6440-444d-82d4-35b10e1394c7
/boot xfs defaults 0 0
/dev/mapper/cl-swap swap swap defaults 0 0
\S
Kernel \r on an \m
10、 請總結描述用戶和管理類命令的使用方法并完成以下練習:
(1)、創建distro,其GID為2016
groupadd -g2016 distro
(2)、創建用戶mandriva,其ID號為1005;基本組為distro
useradd mandriva -u1005 -gdistro
(3)、創建用戶mageia,其ID號為1100,家目錄為/home/linux
useradd mageia -u1100 -d
/home/linux
(4)、給用戶mageia添加密碼,密碼為mageedu
echo ‘mageedu’ | passwd –stdin
mandriva
(5)、刪除mandriva,但保留其家目錄
userdel mandriva
(6)、創建用戶slcakware,其ID號為2002,基本組為distro,附加組為peguin
useradd slackware -u 2002 -g distro
-G peguin
(7)、修改slackware的默認shell為/bin/tcsh
usermod -s /bin/tcsh slackware
(8)、為用戶slackware新增附加組admins
usermod -a -G admins slackware
原創文章,作者:N27_flypig,如若轉載,請注明出處:http://www.www58058.com/84291
這次作業考察的是些基礎的操作命令,熟練掌握,在以后的工作中會更加的得心應手