linux作业--第三周

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

[root@localhost ~]# cat /etc/passwd | grep -v  /sbin/nologin | wc -l
5
[root@localhost ~]# cat /etc/passwd | grep -v  /sbin/nologin | cut -d: -f1
root
sync
shutdown
halt
yc

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

[root@localhost ~]# cat /etc/passwd | cut -d: -f1,3,7 | sort -t: -k2 -n | tail -n 1
nfsnobody:65534:/sbin/nologin
[root@localhost ~]# cat /etc/passwd | cut -d: -f1,3,7 | sort -t: -k2 -rn | head -n1
nfsnobody:65534:/sbin/nologin

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

[root@localhost ~]# netstat -atunl | grep "ESTABLISHED" | tr -s  " " |cut -d " " -f5 | cut -d: -f1 | uniq -c | sort -nr

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

vim disk.sh
#!/bin/bash
BEGIN="\e[1;35m"
END="\e[0m"
echo -e "${BEGIN}`df | grep /dev/sda | grep -o '[0-9]\+%'`${END}"
[root@localhost ~]# chmod a+x dish.sh 
[root@localhost ~]# ./dish.sh 
73%
或使用
[root@localhost ~]# df | grep "^/dev/sd" | grep -Eo '[0-9]+%' |grep -Eo '[0-9]+' | sort -rn| head -n1

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

vim systeminfo.sh
#!/bin/bash
#显示当前主机系统信息,包括:主机名,IPv4地址,操作系统版本,内核版本,CPU型号,内存大小,硬盘大小
BEGINCOLOR="\e[1;35m"
ENDCOLOR="\e[0m"

echo -e "My hostname is ${BEGINCOLOR}`hostname`$ENDCOLOR"
echo -e "IP address is ${BEGINCOLOR}`ifconfig eth0  |grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}'|head -n1`$ENDCOLOR"
echo -e "OS version is ${BEGINCOLOR}`cat /etc/redhat-release`$ENDCOLOR"
echo -e "Kernel version is ${BEGINCOLOR}`uname -r`$ENDCOLOR"
echo -e "CPU type is ${BEGINCOLOR}`lscpu|grep "Model name" |cut -d: -f2 |tr -s " "`$ENDCOLOR"
echo -e "Memtotol is ${BEGINCOLOR}`cat /proc/meminfo |head -n1 |grep -Eo '[0-9]+.*'`$ENDCOLOR"
echo -e "Disk space is ${BEGINCOLOR}`lsblk |grep 'sda\>'|grep -Eo '[0-9]+[[:upper:]]'`$ENDCOLOR"

[root@localhost ~]# chmod a+x systeminfo.sh 

[root@localhost ~]# ./systeminfo.sh 
My hostname is localhost.localdomain
IP address is 192.168.42.200
OS version is CentOS Linux release 7.2.1511 (Core) 
Kernel version is 3.10.0-327.el7.x86_64
CPU type is  Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz
Memtotol is 1001332 kB
Disk space is 20G

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

posted @ 2021-11-01 22:40  咚咚小孩  阅读(39)  评论(0)    收藏  举报