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

相关推荐

  • 如何理解云计算中IaaS、PaaS和SaaS?很简单,就像吃货想吃披萨了…

                                                      &nbsp…

    2015-04-17
  • Gdevops 2017全球敏捷运维峰会【北京站】限时免费!

    Introduction 全球敏捷运维峰会 打造敏捷与运维领域标杆峰会! 2017年全球敏捷运维峰会(Gdevops, Global Devops Summit)将于2017年在成都、上海、北京、广州四城全面启动,本次Gdevops 2017全球敏捷运维峰会【北京站】由上海市经济和信息化委员会指导,上海市云计算产业促进中心、DBAplus社群主办,数十家媒体…

    Linux干货 2017-08-02
  • Python函数式编程指南(三):迭代器

    这一篇我们将讨论迭代器。迭代器并不是函数式编程特有的东西,但它仍然是函数式编程的一个重要的组成部分,或者说是一个重要的工具。 转载请注明原作者和原文地址:) 3. 迭代器 3.1. 迭代器(Iterator)概述 迭代器是访问集合内元素的一种方式。迭代器对象从集合的第一个元素开始访问,直到所有的元素都被访问一遍后结束。 迭代器不能回退,只能往前进行迭代。这并…

    Linux干货 2015-03-11
  • 网络基础命令与配置文件地址

    centos6查看网卡dmesg | grep -i ethethtool -i eth0卸载网卡驱动modprobe -r e1000rmmod e1000装载网卡驱动modprobe e1000网络配置,静态指定system-config-network-tui 字符界面式网络配置ip addr add IP地址 via 网关IP地址动态分配在/etc/…

    2017-09-09
  • bonding命令

    一、Bonding是什么将多块网卡绑定同一IP地址对外提供服务,可以实现高可用或者负载均衡。直接给两块网卡设置同一IP地址是不可以的。通过bonding,虚拟一块网卡对外提供连接,物理网卡的被修改为相同的MAC地址。 二、Bonding工作模式Mode 0 (balance-rr)轮转(Round-robin)策略:从头到尾顺序的在每一个slave接口上面发…

    2017-09-10
  • linux基础学习之AWK

    内容: 1、awk输出(print、printf) 2、awk变量(内建变量和定义变量) 3、awk数组 4、awk重定向输出 5、awk操作符 6、awk常见模式类型 7、awk控制及循环语句 8、awk内置函数 awk:(其名称得自于它的创始人 Alfred Aho 、Peter Weinberger 和 Brian Kernighan 姓氏的首个字母)…

    Linux干货 2016-09-22