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

相关推荐

  • Linux基础:计算机的组成及其功能

    1. 描述计算机的组成及其功能。
    2. 按系列罗列Linux的发行版,并描述不同发行版之间的联系与区别。
    3. 描述Linux的哲学思想,按照自己的理解对其解释性描述。
    4. 说明Linux系统上命令的使用格式;详细介绍ifconfig、echo、tty、startx、export、pwd、history、shutdown、poweroff、reboot、hwclock、date等命令使用,配合相应实例阐述。
    5. 如何获取帮助信息,描述man文档章节划分。
    6. 罗列发行版基础目录名称命名法则及功用规定。

    2017-12-07
  • haproxy实验

    实验1: 部署discuz 1、  不做会话绑定 基于roundrobin —————————10.1.72.40|30————————&#821…

    Linux干货 2016-12-05
  • 网卡别名及多网卡配置

    网卡别名 对于要在不同网段环境中使用的设备有很大的帮助。     要使用网卡别名首先要关闭NetworkManager这个服务,防止在后续操作中引起不必要的冲突。 [root@laodeng6 ~]# chkconfig NetworkManager off [root@laod…

    Linux干货 2016-09-06
  • linux 用户与组管理详解

    ##用户与组的分类 Linux系统对用户分配如下: -系统管理员:root -普通用户:普通用户分为以下两种           系统用户:系统用户通常是不可登陆的,执行某些服务及进程的帐号           登录用户:一般用户,    …

    Linux干货 2017-04-05
  • 马哥教育网络班20期+第3周课程练习

    1、列出当前系统上所有已经登录的用户的用户名,注意:同一个用户登录多次,则只显示一次即可。    w | grep "^root\>" |sort -u   2、取出最后登录到当前系统的用户的相关信息。    who |   3、取出当前系统上被用户当作…

    Linux干货 2016-06-26
  • Python修饰器的函数式编程

    Python的修饰器的英文名叫Decorator,当你看到这个英文名的时候,你可能会把其跟Design Pattern里的Decorator搞混了,其实这是完全不同的两个东西。虽然好像,他们要干的事都很相似——都是想要对一个已有的模块做一些“修饰工作”,所谓修饰工作就是想给现有的模块加上一些小装饰(一些小功能,这些小功能可能好多模块都会用到),但又不让这个小…

    Linux干货 2016-08-15