8月5日作业

课堂练习:

1、找出ifconfig命令结果中本机的所有IPv4地址

[root@localhost ~]# ifconfig | tr -s " " |head -2 | tail -1 |cut -d: -f2 | cut -d" " -f1

2、查出分区空间使用率的最大百分比值

[root@localhost ~]# df -h | tr -s " " |cut -d" " -f5 | sort -n

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

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

4、查出/tmp的权限,以数字方式显示 ?

[root@localhost ~]# stat /tmp/ | tr -s " " |head -4 | tail -1| cut -d/ -f1 | cut -d"(" -f2

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

[root@localhost ~]# netstat -net |tr -s " " | cut -d" " -f5 |cut -d":" -f1 |uniq -c

6、显示/proc/meminfo文件中以大小s开头的行;(要求:使 用两种方式) 

[root@localhost ~]# grep -i ^s /proc/meminfo
[root@localhost ~]# grep  "^[s|S]" /proc/meminfo

7、显示/etc/passwd文件中不以/bin/bash结尾的行 

[root@localhost ~]# grep -v "/bin/bash" /etc/passwd

8、显示用户rpc默认的shell程序 

[root@localhost ~]# grep "\<rpc" /etc/passwd -w |cut -d: -f7

9、找出/etc/passwd中的两位或三位数 

[root@localhost ~]# grep "[0-9][0-9][0-9]\?" /etc/passwd
[root@localhost ~]#  grep "\<[0-9]\{2,3\}\>" /etc/passwd

10、显示/etc/grub2.cfg文件中,至少以一个空白字符开头的 且后面存非空白字符的行 

[root@nzg7 ~]# grep "^[[:space:]]\+[^[:space:]]" /etc/grub2.cfg

11、找出“netstat -tan”命令的结果中以‘LISTEN’后跟任意多 个空白字符结尾的行 

[root@localhost ~]# netstat -tan | grep "LISTEN[[:space:]]*$"

12、添加用户bash、testbash、basher以及nologin(其shell为 /sbin/nologin),而后找出/etc/passwd文件中用户名同shell名 的行

[root@localhost ~]# grep "^\([^:]\+\>\).*\<\1\>$" /etc/passwd

13、显示三个用户root、mage、wang的UID和默认shell 

[root@localhost ~]# grep -E "^(root|mage|wang)\b" /etc/passwd |cut -d: -f1,3,7

14、找出/etc/rc.d/init.d/functions文件中行首为某单词(包 括下划线)后面跟一个小括号的行

[root@localhost ~]# grep -E "^[_[:alpha:]]+\(\)" /etc/rc.d/init.d/functions -o

15、使用egrep取出/etc/rc.d/init.d/functions中其基名

[root@localhost ~]# echo "/etc/sysconfig/network-scripts/ifcfg-eth0/" | grep -E "[^/]+/?$" -o |grep -E [^/]+ -o

16、使用egrep取出上面路径的目录名 

[root@localhost ~]# echo "/etc/sysconfig/network-scripts/ifcfg-eno16777736/" | grep -E -o "^/.*[^/]" |grep -E -o "^/.*/"

17、统计以root身份登录的每个远程主机IP地址的登录次数 

[root@localhost ~]# last |tr -s " "|cut -d" " -f1,3 |grep "^root [[:digit:]]" |sort -n|uniq -c

18、利用扩展正则表达式分别表示0-9、10-99、100-199、 200-249、250-255 

[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]

19、显示ifconfig命令结果中所有IPv4地址

[root@localhost ~]# ifconfig |grep -E "(\<([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\>\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])"

课后作业:

1、取本机ip地址

[root@localhost ~]# ifconfig |grep -E "(\<([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\>\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])"

2、取各分区利用率的数值

[root@localhost ~]# df -h | tr -s " " |cut -d" " -f5 |tr -sc [0-9] '\n' |sort -n

3、统计/etc/init.d/functions 文件中每个单词出现的次数,并按频率从高到低显示

[root@localhost ~]# cat /etc/init.d/functions |grep -E "\<[[:alpha:]]+\>" -o |sort |uniq -c |sort -n

4、/etc/rc.d/init.d/functions或/etc/rc.d/init.d/functions/"  取目录名

echo "/etc/rc.d/init.d/functions/" | grep -E "^/.*[^/]" -o |grep -E "^/.*/" -o

原创文章,作者:闹钟哥,如若转载,请注明出处:http://www.178linux.com/31726

(0)
闹钟哥闹钟哥
上一篇 2016-08-15 14:31
下一篇 2016-08-15 14:31

相关推荐

  • shell脚本总结

    shell进阶:列表生成方式:列表生成方式:(1) 直接给出列表 以空白为间隔(2) 整数列表:(a) {start..end}(b) $(seq [start [step]] end)(3) 返回列表的命令$(COMMAND)(4) 使用glob,如:.sh(5) 变量引用;$@, $while read line(用法)(用于遍历文件,进行处理…

    Linux干货 2017-07-10
  • 马哥Linux第六周作业

    网络管理 进程查看及管理之ps,top,htop,dstat,vmstat

    2018-01-20
  • HA高可用集群学习笔记

    前言   什么是HA?HA做什么用的?   HA(High Available)是高可用集群,是保证业务不中断性的有效解决方案;通常HA集群部署在多个节点,正在提供服务的节点成为活动节点,没有提供服务的是非活动节点;当活动节点发生故障,非活动节点会转为活动节点,向外提供服务,以保证业务的连续性;这就是HA。 一、HA(High Avail…

    Linux干货 2015-06-30
  • 记事本操作的小小小技巧

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://jeffyyko.blog.51cto.com/28563/140063       大家在查看文本文件的时候,如果内容很多,想快速到达某一位置可能比较麻烦,这时如果按住shift,再点击右侧…

    Linux干货 2015-03-26
  • 马哥门徒Linux运维课程笔记-第1天03讲 计算机及操作系统基础

    第1天03讲 计算机及操作系统基础   ◆  市面上主流Unix厂商简介         由于Unix系统的流行,当时行业中的主流大厂商都根据SysV或BSD开发了自己的版本,主要分类如下:       ●  IBM公司根据自己CPU硬件架…

    Linux干货 2015-03-23
  • Linux无人值守安装

    前言     通常情况下,我们安装Linux操作系统的时候需要从光盘启动,通过系统光盘bootloader启动安装程序,进入交互式安装模式,由用户配置安装选项,如磁盘分区、选择安装包等操作;安装完毕后重启结束安装。在生产环境中,成百上千台服务器需要安装操作系统的时候如果也采用交互式安装模式,无疑是极其低效的。本文主要介…

    Linux干货 2015-05-18