查看當(dāng)前操作系統(tǒng)版本:
[root@MiWiFi-R4A-srv ~]# cat /etc/redhat-release
CentOS Linux release 7.7.1908 (Core)
查看當(dāng)前操作系統(tǒng)的版本
內(nèi)核版本:
unname -r
cpu 型號:ls? ?cpu
查看硬盤大幸菁狻:lsblk
sda 8:0 0 200G 0 disk 這個就是硬盤的大小
查看內(nèi)存的大型幻巍:free -h
首先需要找cpu的參數(shù):lscpu|grep "Model name"|cut -d:? -f2|tr -s " "
找到磁盤的大小
lsblk|grep disk|tr -s " " |cut -d " " -f4
查看內(nèi)存
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"
替換 轉(zhuǎn)意:
:.,$s/ is / is \\033[31m/
最后結(jié)果:
[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
變量:
變量:命名的內(nèi)存空間
字符串由操作系統(tǒng)分配到內(nèi)存中币砂,而在內(nèi)存中分配的位置是二進(jìn)制的機器語言才能找打表示,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
當(dāng)同時輸入兩個變量的時候都需要$符號
如果想表示TITLE后面有數(shù)字兩種表示:
echo "$TITLE"1? ?也可以echo {$TITLE}1
刪除變量賦值:
unset (變量)
替換轉(zhuǎn)意:
:%s/\\033\[0m/\$COLOREND/
查看哪些IP連接本機
netstat -an