Linux基础学习(三)(Linux basic learning (III))

统计出/etc/passwd文件中其默认shell为非/sbin/nologin的用户个数,并将用户都显示出来

[root@ct7 ~]# grep -vc "/sbin/nologin" /etc/passwd
[root@ct7 ~]# grep -v "/sbin/nologin" /etc/passwd | cut -d: -f 1

查出用户UID最大值的用户名、UID及shell类型

[root@ct7 ~]# cat /etc/passwd | sort -t: -k3 -n | tail -1 | cut -d: -f1,3,7

统计当前连接本机的每个远程主机IP的连接数,并按从大到小排序

[root@ct7 ~]# w -h | tr -s " "| cut -d " " -f3 | sort | uniq -c | sort -nr

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

`#!/bin/bash

显示当前硬盘分区中空间利用率最大的值

#!/bin/bash

#显示当前硬盘分区中空间利用率最大的值


max_disk=`df -h | tr -s " " | cut -d " "  -f5 | sort -nr | head -1`
echo "当前硬盘分区中空间利用率最大的值: ${max_disk}"
#!/bin/bash

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

echo "主机名:  `hostname`"
echo "IPv4地址:`ip addr show eth0 | grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}' | head -1`"
echo "系统版本:`cat /etc/centos-release`"
echo "内核版本:`uname -r`"
echo "CPU型号: `lscpu | grep -i "model name" | cut -d: -f2 | tr -s " "`"
echo "内存大小:`free -h | grep Mem | tr -s " " ":" | cut -d: -f2` "
echo "硬盘大小:`lsblk | grep 'sda\>' | tr -s " " | cut -d " " -f4`"


————————

Count the number of users whose default shell is non / SBIN / nologin in the / etc / passwd file, and display all users

[root@ct7 ~]# grep -vc "/sbin/nologin" /etc/passwd
[root@ct7 ~]# grep -v "/sbin/nologin" /etc/passwd | cut -d: -f 1

Find out the user name, uid and shell type of the maximum user uid

[root@ct7 ~]# cat /etc/passwd | sort -t: -k3 -n | tail -1 | cut -d: -f1,3,7

Count the number of connections of each remote host IP currently connected to the local machine, and sort by the largest to the smallest

[root@ct7 ~]# w -h | tr -s " "| cut -d " " -f3 | sort | uniq -c | sort -nr

Script disk SH, displays the maximum space utilization in the current hard disk partition

`#!/bin/bash

Displays the maximum space utilization in the current hard disk partition

#!/bin/bash

#显示当前硬盘分区中空间利用率最大的值


max_disk=`df -h | tr -s " " | cut -d " "  -f5 | sort -nr | head -1`
echo "当前硬盘分区中空间利用率最大的值: ${max_disk}"
#!/bin/bash

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

echo "主机名:  `hostname`"
echo "IPv4地址:`ip addr show eth0 | grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}' | head -1`"
echo "系统版本:`cat /etc/centos-release`"
echo "内核版本:`uname -r`"
echo "CPU型号: `lscpu | grep -i "model name" | cut -d: -f2 | tr -s " "`"
echo "内存大小:`free -h | grep Mem | tr -s " " ":" | cut -d: -f2` "
echo "硬盘大小:`lsblk | grep 'sda\>' | tr -s " " | cut -d " " -f4`"