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

相关推荐

  • linux 网络管理

    1、ifconfig命令格式: ifconfig[interface] 查看IP ifconfig-a 查看全部网卡信息 ifconfigIFACE [up|down] 网卡开启关闭 ifconfigIFACE IP/netmask [up] ifconfigIFACE IP netmask NETMASK 命令立即生效,不能永久保存  &nbsp…

    Linux干货 2017-08-20
  • 计算机;GPL等开源协议;Linux 哲学思想的炼成;MBR & GPT—fazion in magedu 20.July

    入门Linux的基础知识 fazionlan blog in 178Linux.July 22nd. 第一台计算机 1946第一台计算机ENIAC(electronic numerical integrator and calculator)在美国滨州大学诞生,是美国奥伯丁武器试验场为了满足计算弹道而研制的 冯诺依曼体系结构:1946年数学家提出运算器、控制…

    Linux干货 2016-07-29
  • 设计模式 ( 十二 ) 职责链模式(Chain of Responsibility)(对象行为

    1.概述        你去政府部门求人办事过吗?有时候你会遇到过官员踢球推责,你的问题在我这里能解决就解决,不能解决就推卸给另外个一个部门(对象)。至于到底谁来解决这个问题呢?政府部门就是为了可以避免屁民的请求与官员之间耦合在一起,让多个(部门)对象都有可能接收请求,将这些(部门)对象连接成一条链,并且沿着这条链传递…

    Linux干货 2015-07-15
  • linux 系统启动流程探讨

    linux系统启动流程: linux系统启动流程,按层次分的话,可以分为内核空间的启动与用户空间的启动。 下面先说说内核空间的启动流程。 一个linux要跑起来,在最简陋的情况下,必须有:kernel , lib ,application kernel功能:加载驱动程序,内存管理,进程管理,文件系统,网络管理,安全管理,glibc 库: 是一个函数的集合,每…

    Linux干货 2017-04-11
  • Linux网络属性配置,计算机基础

    Linux网络属性配置,计算机基础 Linux网络属性配置(1): 计算机网络通信:TCP/IP 通过流式化数据相互通信,通过双方一致的时钟频率来完成信号传输; 有两种方式传输:同步传输,异步传输; 借助于介质传输:同轴电缆、网线、无线等; 要想相互通信,也要必须遵循一种(复杂)组织机制,就产生了协议; 通过把协议分层,来分别解决传输过程中各种复杂的操作; …

    Linux干货 2016-09-05
  • Linux文件查找命令详解

    Linux中在文件系统上查找符合条件的文件,实现工具有locate和find locate: 1.它是依赖于事先索引构建好的数据库进行查找的。更新它的数据库有两种方式,一种是系统定期自动更新,另一种是执行命令updatedb手动更新数据库。 注意:索引构建过程需要遍历整个根文件系统,极消耗资源 2.它的工作特性: 1.因为是基于数据库实现的,所以查找速度快(…

    Linux干货 2017-04-10