第三周作业

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

[root@zabbix-test ~]$grep -vE '(/sbin/nologin)$' /etc/passwd | cut -d : -f1 | cat -n
     1  root
     2  sync
     3  shutdown
     4  halt
     5  mysql
     ...省略

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

[root@zabbix-test ~]$cut -d : -f1,3,7 /etc/passwd | sort -t : -k2 -nr | head -n1
user10:2013:/bin/bash

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

[root@zabbix-test ~]$w -h | tr -s ' ' | cut -d' ' -f3 | sort | uniq -c | sort -nr
      1 192.168.9.186

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

grep:
#!/bin/bash
echo "当前硬盘分区中空间利用率最大的值是`df -h | tr -s ' '|cut -d' ' -f5 | sort -nr | head -n1`"

sed:
#!/bin/bash
echo "当前硬盘分区中空间利用率最大的值是`df -h | sed -nE 's/.* ([0-9]{1,3}%).*/\1/p' | sort -nr | sed -n '1p'`
image.png

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

#!/bin/bash
echo  主机名:      `hostname`
echo  ipv4地址:    ` ifconfig | grep -oE '([0-9]{1,3}\.){1,3}[0-9]{1,3}' | head -n1`
echo  操作系统版本:`lsb_release -a | tail -n +3 | head -n1 | tr -d '\t' | cut -d: -f2`
echo  内核版本:    `uname -r`
echo  CPU型号:     `lscpu | tail -n +13|head -n1 | tr -s ' '  |cut -d: -f2`
echo  内存大小:    `lsmem | tail -n +6|head -n1 | tr -s ' '|cut -d: -f2`
echo  硬盘大小:    `lsblk | tail -n +2|head -n1 |tr -s ' ' | cut -d' ' -f4`

image.png

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

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1、复制/etc/profile至/tmp/目录,用查找替换命令删除/tmp/profile文件中的 行首的空白字...
    马晖阅读 145评论 0 0
  • 第一题、复制/etc/profile至/tmp/目录,用查找替换命令删除/tmp/profile文件中的 行首的空...
    左旋阅读 119评论 0 0
  • 1、编写脚本/root/bin/backup.sh,可实现每日将/etc/目录备份到/root/etc-YYYY-...
    Yann1阅读 270评论 0 0
  • 1、复制/etc/profile至/tmp/目录,用查找替换命令删除/tmp/profile文件中的 行首的空白字...
    记忆终泛白阅读 155评论 0 0
  • 表情是什么,我认为表情就是表现出来的情绪。表情可以传达很多信息。高兴了当然就笑了,难过就哭了。两者是相互影响密不可...
    Persistenc_6aea阅读 125,857评论 2 7