- 统计出/etc/passwd文件中其默认shell为非/sbin/nologin的用户个数,并将用户都显示出来
[user1@CentOS test]$ grep -v ‘\(.*/sbin/nologin$\)$‘ /etc/passwd|cut -d: -f1
root
sync
shutdown
halt
mageia
user1
user2
user3
[user1@CentOS test]$ grep -v ‘\(.*/sbin/nologin$\)$‘ /etc/passwd|cut -d: -f1|wc -l
8
- 查出用户UID最大值的用户名、UID及shell类型
[user1@CentOS test]$ cat /etc/passwd|cut -d: -f1,3,7|sort -t: -k2 -nr |head -1
nobody:65534:/sbin/nologin
- 统计当前连接本机的每个远程主机IP的连接数,并按从大到小排序
[root@CentOS ~]# ss -nt|tail -n +2|grep -Eo ‘([0-9]{1,3}\.){3}[0-9]{1,3}:[0-9]+[[:space:]]+$‘|grep -Eo ‘([0-9]{1,3}\.){3}[0-9]{1,3}‘|sort -n| uniq -c|sort -nr
-
编写脚本disk.sh,显示当前硬盘分区中空间利用率最大的值
[root@centos7-1-160 ~]# bash disk.sh 12 [root@centos7-1-160 ~]# cat disk.sh #/bin/bash disk=/data/disk.log disk1=/data/disk1.log df -h > $disk grep ‘^/dev/s‘ $disk > $disk1 grep -o ‘[0-9]\{1,3\}%‘ $disk1 > $disk grep -o ‘[0-9]\{1,3\}‘ $disk > $disk1 echo `cat $disk1 | sort -nr | head -1`
[root@centos7-1-160 ~]# bash disk.sh 12 [root@centos7-1-160 ~]# cat disk.sh #/bin/bash echo `df -h| grep ‘^/dev/‘|tr -s ‘ ‘ :|grep -o ‘[0-9]\{1,3\}%‘|grep -o ‘[0-9]\{1,3\}‘|sort -nr| head -1` [root@centos7-1-160 ~]#
-
编写脚本 systeminfo.sh,显示当前主机系统信息,包括:主机名,IPv4地址,操作系统版本,内核版本,CPU型号,内存大小,硬盘大小
[root@centos7-1-160 ~]# bash systeminfo.sh
HOSTNAME: centos7-1-160
IPADDR: 10.0.0.164
VERSION: 7
KERNEL: 3.10.0-1127.el7.x86_64
CPU: Intel(R)Core(TM)i7-8750HCPU@2.20GHz
MEMORY: 972M
DISK: 150G
[root@centos7-1-160 ~]# cat systeminfo.sh
#/bin/bash
echo HOSTNAME: `hostname`
echo IPADDR: `ifconfig | grep ‘^[[:space:]]\+inet.*[0-9]\+$‘|tr -s ‘ ‘ ! |cut -d! -f3|head -n 1`
echo VERSION: `cat /etc/os-release | grep ‘^VERSION=‘| grep -o ‘[0-9]\+‘`
echo KERNEL: `uname -r`
echo CPU: `lscpu | grep ‘^Model name‘|tr -d ‘ ‘|cut -d : -f2`
echo MEMORY: `free -h| grep ‘^Mem:‘|tr -s ‘ ‘ |cut -d ‘ ‘ -f2`
echo DISK: `lsblk | grep ‘^sd‘|tr -s ‘ ‘ %|cut -d% -f4|grep -o ‘[0-9]\+‘|paste -s -d+ |bc`G
- 20分钟内通关vimtutor(可参考https://yyqing.me/post/2017/2017-02-22-vimtutor-chinese-summary)