Linux学习第三周
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)

浙公网安备 33010602011771号