简单shell脚本练习

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

[root@centos8 ~]# cat desk.sh
#! /bin /bash

echo `df|grep '^/dev/sda'|tr -s " "| cut -d " " -f5| sort -nr| head -1`


 
[root@centos8 ~]# bash desk.sh
11%

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

[root@centos8 ~]# cat systeminfo.sh
#! /bin/bash

echo -e "hostname      :"`hostname`
echo -e "IPv4 address  :"`ifconfig ens33 | grep -Eo '([0-9]{1,3}.){3}[0-9]{1,3}'| head -n1`
echo -e "OS version    :"`cat /etc/redhat-release`
echo -e "KernelVersion :"`uname -r`
echo -e "CPU Model     :"`lscpu| grep '^Model name'| tr -s ":"| cut -d ":" -f2`
echo -e "Memery        :"`free -h| grep '^Mem'| tr -s " "| cut -d " " -f2`
echo -e "Disk          :"`lsblk| grep ^sda| tr -s " " | cut -d " " -f4`
[root@centos8 ~]# bash systeminfo.sh
hostname      :centos8
IPv4 address  :10.0.0.101
OS version    :CentOS Linux release 8.4.2105
KernelVersion :4.18.0-305.3.1.el8.x86_64
CPU Model     : 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz
Memery        :1.9Gi
Disk          :200G

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

  已完成

posted @ 2021-11-29 15:45  gamebear  阅读(114)  评论(0)    收藏  举报