Java教程

第三周(0906~0913)

本文主要是介绍第三周(0906~0913),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
第三周 作业  1、统计出/etc/passwd文件中其默认shell为非/sbin/nologin的用户个数,并将用户都显示出来  
cat /etc/passwd |grep -v‘/sbin/nologin’|wc -l
cat /etc/passwd |grep -v‘/sbin/nologin’|cut -d: -f1
  2、查出用户UID最大值的用户名、UID及shell类型
grep -E `cat /etc/passwd |cut -d: -f3|sort -nr|head -1` /etc/passwd

  3、统计当前连接本机的每个远程主机IP的连接数,并按从大到小排序  
ss -nta|grep ESTAB|awk -F" " '{print $NF}'|sed s#::ffff:##g |awk -F":" '{print $1}'|sort|uniq -c|sort -rn

 

 

4、编写脚本disk.sh,显示当前硬盘分区中空间利用率最大的值
df |grep -E '^/dev/sd'|grep -oE '([0-9]+)%' |tr -d '%'|sort -nr|head -1

  5、编写脚本 systeminfo.sh,显示当前主机系统信息,包括:主机名,IPv4地址,操作系统版本,内核版本,CPU型号,内存大小,硬盘大小
[root@centos7 ~]# vim test.sh
#!/bin/bash
# This is a shell script for print system infomations.
 
COLOR_B="\e[0;33m"
COLOR_E="\e[0m"
 
echo "-------------------------------------system infomation------------------------------------"
echo -e "Hostname is ${COLOR_B}`hostname`$COLOR_E"
echo -e "IPv4 address is ${COLOR_B}`ifconfig ens33 |grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}'|head -n1`$COLOR_E"
echo -e "OS version is ${COLOR_B}`cat /etc/redhat-release`$COLOR_E"
echo -e "Kernel version is ${COLOR_B}`uname -r`$COLOR_E"
echo -e "CPU info is ${COLOR_B}`lscpu|grep "Model name" |cut -d: -f2 |tr -s " "`$COLOR_E"
echo -e "MEM is ${COLOR_B}`cat /proc/meminfo |head -n1 |grep -Eo '[0-9]+.*'`$COLOR_E"
echo -e "Disk space is ${COLOR_B}`lsblk |grep -E 'sd[ab]+\>'|awk -F" " 'BEGIN{ORS=" "}{print $1,$4}'`$COLOR_E"
~
  6、20分钟内通关vimtutor(可参考https://yyqing.me/post/2017/2017-02-22-vimtutor-chinese-summary)  这个好玩。其他发现:个人尝试后,d命令应该是剪切。 dd 剪切光标所在行,按p 又回来了,比如:3dd 表示剪切3行,光标移动到需要放置的位置,p黏贴。
这篇关于第三周(0906~0913)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!