文本处理工具和正则表达式以及shell编程

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

[10:27:44 root@CentOS8 ~]\ [#grep -v '/sbin/nologin' /etc/passwd |cut -d: -f1

root sync shutdown halt zhao user1 user2 user3

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

[10:36:08 root@CentOS8 ~]\ [#cat /etc/passwd |cut -d: -f1,3,7 |sort -nr -k2 -t: |head -n1

nobody:65534:/sbin/nologin

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

[10:44:31 root@CentOS8 ~]\ [#ss -nt|grep "^ESTAB"|tr -s " " : |cut -d: -f6|sort -nr|uniq -c|sort -nr

1 192.168.147.1

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

#!/bin/bash

# ###################################

#Auntor: Zhaoyaxuan

#QQ: 907620409

#Email: 907620409@qq.com

#Date: 2021-07-24 10:51:14

#Description: script ###################################

echo -e "硬盘分区中空间利用率最大值为:" df |egrep -o "[0-9]{1,3}%" |sort -nr|head -n1

[10:52:52 root@CentOS8 data]\ [#bash disk.sh

硬盘分区中空间利用率最大值为: 22%

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

#!/bin/bash

# ###################################

#Auntor: Zhaoyaxuan

#QQ: 907620409

#Email: 907620409@qq.com

#Date: 2021-07-24 10:55:46

#Description: script ###################################

echo "HOSTNAME is : hostname"

echo "IPADDR is : ifconfig ens33|head -n 2|tail -n 1|tr -s " " : |cut -d: -f3"

echo "OSVERSION is : cat /etc/redhat-release"

echo "KERNEL is : uname -r"

echo "CPU is :lscpu |grep "Model name"|tr -s ' '|cut -d: -f2"

echo "MEMORY is :free -h|grep "Mem"|tr -s ' ' :|cut -d: -f2"

echo "DISK is:lsblk|grep '^sd'|tr -s ' ' :|cut -d: -f5"

[11:26:42 root@CentOS8 data]\ [#bash systeminfo.sh

HOSTNAME is : CentOS8.localdomain

IPADDR is : 192.168.147.128

OSVERSION is : CentOS Linux release 8.3.2011

KERNEL is : 4.18.0-240.el8.x86_64

CPU is : 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz

MEMORY is :1.7Gi

DISK is:200G

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

完成

posted @ 2021-07-25 22:54  Zhaoyaxuan  阅读(56)  评论(0)    收藏  举报