ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

N51期第四次作业

2020-12-21 07:02:47  阅读:147  来源: 互联网

标签:head cut grep N51 tr 作业 echo 0m 第四次


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

[root@centos8mini ~]# cat /etc/passwd | grep -v '/sbin/nologin' | cut -d : -f 1
root
sync
shutdown
halt
xyj

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

[root@centos8mini ~]# cat /etc/passwd | cut -d : -f 1,3,7 | sort -t : -k 2 -n -r | head -1
nobody:65534:/sbin/nologin

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

[root@centos8mini ~]# ss -nt | tail -n +2 | tr -s ' ' : | cut -d : -f 6 | sort | uniq -c | sort -n -r

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

[root@centos8mini scripts]# cat disk.sh 
#!/bin/bash
echo -e "\e[1;31m`df -hT | grep -Eo '([0-9]{1,2}|100)%' | sort -n -r | tr -d % | head -1`\e[0m"

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

#!/bin/bash
echo -e "\e[1;32m**********************主机系统信息**********************\e[0m"
echo -e "\e[1;35m主机名:       `hostname`\e[0m"
echo -e "\e[1;35mIPv4地址:     `ifconfig ens33 | grep -Eo '(([0-9]|[1-9][0-9]|1[0-9]{,2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{,2}|2[0-4][0-9]|25[0-5])' | head -1`\e[0m"
echo -e "\e[1;35m操作系统版本: `cat /etc/redhat-release`\e[0m"
echo -e "\e[1;35m内核版本:     `uname -r`\e[0m"
echo -e "\e[1;35mCPU型号:     `lscpu | grep 'Model name' | tr -s ' ' | cut -d : -f 2`\e[0m"
echo -e "\e[1;35m内存大小:     $(free -h | tr -s ' ' : | cut -d : -f 2 | tail -n $(echo "`free -h | wc -l`-1" | bc) | head -1)\e[0m"
echo -e "\e[1;35m硬盘大小:     `lsblk | grep sda | head -1 | tr -s ' ' : | cut -d : -f 5`\e[0m"
echo -e "\e[1;32m********************************************************\e[0m"

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

标签:head,cut,grep,N51,tr,作业,echo,0m,第四次
来源: https://blog.51cto.com/3958535/2568340

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有