shell脚本

查看当前操作系统版本:

[root@MiWiFi-R4A-srv ~]# cat /etc/redhat-release

CentOS Linux release 7.7.1908 (Core)

查看当前操作系统的版本

内核版本:

unname -r

cpu 型号:ls   cpu

查看硬盘大小:lsblk

sda 8:0 0 200G 0 disk 这个就是硬盘的大小

查看内存的大小:free -h

首先需要找cpu的参数:lscpu|grep "Model name"|cut -d:  -f2|tr -s " "

找到磁盘的大小

lsblk|grep disk|tr -s " " |cut -d " " -f4

查看内存

free -h|grep Mem|tr -s " " |cut -d " " -f2

最后连成一起:

12 echo OS Verion is `cat /etc/redhat-release`

13 echo kernal version is `uname -r`

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

15 echo Disk space is `lsblk|grep disk|tr -s " " |cut -d " " -f4`

16 echo Memory size is `free -h|grep Mem|tr -s " " |cut -d " " -f2`

加颜色,is替换:

12 echo -e "OS Verion is \033[31m`cat /etc/redhat-release`\033[0m"

13 echo -e  "kernel version is \033[31m`uname -r`\033[0m"

14 echo -e "CPU type is \033[31m`lscpu|grep 'Model name'|cut -d: -f2|tr -s ' '`\033[0m"

15 echo -e "Disk space is \033[31m`lsblk|grep disk|tr -s ' ' |cut -d ' ' -f4`\033[0m"

16 echo -e "Memory size is \033[31m`free -h|grep Mem|tr -s ' ' |cut -d ' ' -f2`\033[0m"

替换 转意:

:.,$s/ is / is \\033[31m/

最后结果:

[root@localhost /data/scripts37]# bash systeminfo.sh

OS Verion is CentOS Linux release 7.7.1908 (Core)

kernel version is 3.10.0-1062.el7.x86_64

CPU type is  Intel(R) Core(TM) i5-6300HQ CPU @ 2.30GHz

Disk space is 200G

Memory size is 1.8G

变量:

变量:命名的内存空间

字符串由操作系统分配到内存中,而在内存中分配的位置是二进制的机器语言才能找打表示,shell里面把这个物理位置表示成一个名称name,而通过这个name来找到这个字符串 






[root@localhost /data/scripts37]# NAME=mage

[root@localhost /data/scripts37]# echo $NAME

mage

[root@localhost /data/scripts37]# TTTLE=ceo

[root@localhost /data/scripts37]# echo $NAME $TTTLE

mage ceo

当同时输入两个变量的时候都需要$符号

如果想表示TITLE后面有数字两种表示:

echo "$TITLE"1   也可以echo {$TITLE}1

删除变量赋值:

unset (变量)

替换转意:

:%s/\\033\[0m/\$COLOREND/

查看哪些IP连接本机

netstat -an

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容