明20210821

文本处理和shell编程基础

1、统计出/etc/passwd文件中其默认shell为非/sbin/nologin的用户个数,并将用户都显示出来

 

2、查出用户UID最大值的用户名、UID及shell类型

 

3、统计当前连接本机的每个远程主机IP的连接数,并按从大到小排序

 

 

4、编写脚本disk.sh,显示当前硬盘分区中空间利用率最大的值

[root@10-100-14-129 bin]# more disk.sh
#!/bin/bash
#显示当前硬盘的空间利用率最大值
df -h | awk '{print $5,$6}'| tr -s " " "%" | cut -d% -f1 | sort -rn | head -n1

 

5、编写脚本 systeminfo.sh,显示当前主机系统信息,包括:主机名,IPv4地址,操作系统版本,内核版本,CPU型号,内存大小,硬盘大小 

[root@10-100-14-129 bin]# sh systeminfo.sh
The hostname is:10-100-14-129
The IPV4 address is:10.100.14.129
The OS version is: CentOS Linux release 8.4.2105
The Kernel Version is: 4.18.0-305.10.2.el8_4.x86_64
The CPU is: IntelCoreProcessor(Skylake)
The Memorysize is: 7742MB
The disksize is: 500 GiB
[root@10-100-14-129 bin]#
[root@10-100-14-129 bin]#
[root@10-100-14-129 bin]#
[root@10-100-14-129 bin]# more systeminfo.sh
#!/bin/bash
echo "The hostname is:$(hostname)"
echo "The IPV4 address is:$(hostname -I)"
echo "The OS version is: $(cat /etc/redhat-release )"
echo "The Kernel Version is: $(uname -r )"
echo "The CPU is: $(lscpu | grep "Model name" | head -1 |cut -d: -f2 | tr -d " ")"
echo "The Memorysize is: $(echo `cat /proc/meminfo |head -n1|cut -d: -f2|tr -d ' '|tr -cd "[0-9]"`/1024|bc)MB"
echo "The disksize is: $(fdisk -l | head -n1 | cut -d: -f2 | cut -d, -f1)"

6、20分钟内通关vimtutor(可参考https://yyqing.me/post/2017/2017-02-22-vimtutor-chinese-summary)

 

posted on 2021-09-08 12:17  明20210821  阅读(40)  评论(1编辑  收藏  举报

导航