Linux學習第三週
阿新 • • 發佈:2021-12-06
1、統計出/etc/passwd檔案中其預設shell為非/sbin/nologin的使用者個數,並將使用者都顯示出來
[root@localhost ~]# grep -v '/sbin/nologin' /etc/passwd root:x:0:0:root:/root:/bin/bash sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt
2、查出使用者UID最大值的使用者名稱、UID及shell型別
[root@localhost ~]# cat /etc/passwd | sort -t: -k3 -n | tail -n1 | cut -d ":" -f 1,3,7 polkitd:999:/sbin/nologin
3、統計當前連線本機的每個遠端主機IP的連線數,並按從大到小排序
[root@localhost ~]# netstat -nt | tr -s ' ' : | cut -d : -f6 | sort | uniq -c | sort -nr
2 192.168.237.1
1 Foreign
4、編寫指令碼disk.sh,顯示當前硬碟分割槽中空間利用率最大的值
[root@localhost ~]# cat disk.sh #!/bin/bash df| tr -s " " | cut -d" " -f5 | sort -n | tail -1 [root@localhost ~]# ./disk.sh 17%
5、編寫指令碼 systeminfo.sh,顯示當前主機系統資訊,包括:主機名,IPv4地址,作業系統版本,核心版本,CPU型號,記憶體大小,硬碟大小
[root@localhost ~]# cat systeminfo.sh #!/bin/bash echo Hostname: `hostname` echo IPv4: `ifconfig ens33 | grep -Eo '([0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3})'| head -1` echo OS.version: `cat /etc/redhat-release` echo Kernel.version: `uname -r` echo CPU: `lscpu | grep "Vendor"| tr -s " "| cut -d " " -f3` echo Mem: `free -h| grep 'Mem' | tr -s " " | cut -d " " -f2` echo Disk `lsblk |grep "^sd" | tr -s " " | cut -d " " -f4` [root@localhost ~]# ./systeminfo.sh Hostname: localhost.localdomain IPv4: 192.168.237 OS.version: CentOS Linux release 7.9.2009 (Core) Kernel.version: 3.10.0-1160.45.1.el7.x86_64 CPU: AuthenticAMD Mem: 3.8G Disk 100G
6、20分鐘內通關vimtutor(可參考https://yyqing.me/post/2017/2017-02-22-vimtutor-chinese-summary)