Linux中shell練習

一、統計出/etc/passwd文件中其默認shell爲非/sbin/nologin的用戶個數,並將用戶都顯示出來shell

grep  -v  '/sbin/nologin'  /etc/passwd   | cut -d: -f 1
            grep  -v  '/sbin/nologin'  /etc/passwd   | cut -d: -f 1 | wc -l

二、查出用戶UID最大值的用戶名、UID及shell類型centos

cat /etc/passwd | cut -d: -f1,3,7 | sort  -t ":" -k 2   -rn | head -1

三、統計當前鏈接本機的每一個遠程主機IP的鏈接數,並按從大到小排序bash

ss -nt  | grep -v State |  tr -s " " : | cut -d: -f6   | sort  | uniq -c | sort -rn

四、編寫腳本disk.sh,顯示當前硬盤分區中空間利用率最大的值ide

[root@centos8 scripts]# cat disk.sh 
        #!/bin/bash
        LIST_DISK_USERD=`df  | grep  '^/dev' | tr -s ' '  | cut -d " " -f 6,5 | sort  -t% -k1 -nr`

        echo   "$LIST_DISK_USERD"

Linux中shell練習

五、編寫腳本 systeminfo.sh,顯示當前主機系統信息,包括:主機名,IPv4地址,操做系統版本,內核版本,CPU型號,內存大小,硬盤大小操作系統

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

            RED="\033[1;31m"
            GREEN="\033[1;32m"
            END="\033[0m"

            echo -e "$GREEN---------------------------------- Host systeminfo------------------------------$END"
            echo -e "HOSTNAME:   $RED `hostname` $END"
            echo -e "IPADDR:     $RED `ifconfig ens33 | egrep -o '([0-9]{1,3}\.){3}[0-9]{1,3}' | head -n1` $END"
            echo -e "OSVERSION:  $RED `cat /etc/system-release` $END"
            echo -e "KERNEL:     $RED `uname -r` $END"
            echo -e "CPU:        $RED `lscpu | grep 'Model name' |tr -s ' '  | cut -d: -f2` $END"
            echo -e "MEMORY:     $RED `free -h|grep Mem|tr -s ' ' : |cut -d : -f2` $END"
            echo -e "DISK:       $RED `lsblk  | grep '^sda' | tr -s ' ' : | cut -d : -f 1,5` $END"
            echo -e "$GREEN--------------------------------------------------------------------------------$END"

Linux中shell練習

相關文章
相關標籤/搜索