8.5_Linux习题练习和作业

课堂练习题

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

# ifconfig | grep -oE "([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])){3}"

blob.png

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

# df |grep "/dev/sd" | tr -s " " ":" |cut -d: -f1,5 |sort

blob.png

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

# cat /etc/passwd | sort -n -t: -k3 | tail -1 | cut -d: -f1,3,7

blob.png

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

# stat /tmp |grep 'Access' | head -1 | tr " " ":" | cut -d: -f3 |tr -cd "[[:digit:]]"

blob.png

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

[root@centos7 ~]# netstat -nt | grep "tcp"|tr -s " " ":"|cut -d: -f6 |sort |uniq -c

blob.png

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

(1)grep "^[sS]" /proc/meminfo

blob.png

(2)grep -i "^s" /proc/meminfo

blob.png

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

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

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

grep "^rpc\>" /etc/passwd | cut -d: -f1,7

blob.png

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

[root@centos7 ~]# grep -E "\b([1-9][0-9]|[1-9][0-9]{2})\b" /etc/passwd

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

[root@centos7 ~]# grep "^\s[^\s].*" /etc/grub2.cfg

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

[root@centos7 ~]# netstat -tan | grep "LISTEN\s*$"

blob.png

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

[root@centos7 ~]# grep -E "(^[[:alnum:]]+)\b.*/\1{1}$" /etc/passwd

blob.png

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

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

blob.png

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

[root@centos7 ~]# egrep "\w+\(\).*" /etc/rc.d/init.d/functions

blob.png

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

[root@centos7 ~]# echo "/etc/rc.d/init.d/functions" | egrep "\w*\.?\w*$"

blob.png

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

[root@centos7 ~]# last | grep "root" | egrep -o "([0-9]|[0-9]{2}|[0-9]{3})(\.([0-9]|[0-9]{2}|[0-9]{3})){3}"|sort|uniq -c

blob.png

17、利用扩展正则表达式分别表示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]

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

[root@centos7 ~]# ifconfig | egrep -o "([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])){3}"

blob.png

作业题

1、取本机ip地址

[root@centos7 ~]# ifconfig|head -2|tail -1|grep -oE "([0-9]|[1-9][0-9]|[1-9][0-9]{2})(\.([0-9]|[1-9][0-9]|[1-9][0-9]{2})){3}"|head -1

blob.png

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

[root@centos7 ~]# df -h | grep "/dev/sd" | tr -s " " ":" | cut -d: -f1,5 | sort

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

[root@centos7 ~]# grep -o "\b[[:alnum:]]*\b" /etc/init.d/functions | sort | uniq -c | sort -n

blob.png

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

[root@centos7 ~]# echo "/etc/rc.d/init.d/functions" | egrep -o "/.*/"

blob.png

5、正则表达式表示身份证号

egrep "\b[1-9]{2}[0-9]{15}[0-9xX]\b"

6、正则表达式表示手机号

egrep "\b1[3-8][0-9]{9}\b"

7、正则表达式表示邮箱

[root@centos7 ~]# egrep -i "\w*@[[:alnum:]]*\.[[:alpha:]]{1,3}\.?[[:alpha:]]{,2}"

8、正则表达式表示QQ号

 [root@centos7 ~]# egrep "\b[1-9][0-9]{4,9}\b"

原创文章,作者:~微风~,如若转载,请注明出处:http://www.178linux.com/30832

(0)
~微风~~微风~
上一篇 2016-08-10
下一篇 2016-08-10

相关推荐

  • 第九周

    1、写一个脚本,判断当前系统上所有用户的shell是否为可登录shell(即用户的shell不是/sbin/nologin);分别这两类用户的个数;通过字符串比较来实现; #!/bin/bash for i in `cut -d':' -f7 /etc/passwd`;do &n…

    Linux干货 2016-09-26
  • lvs nat模型调度双http服务且http上布置discuz

    实验的拓扑图: 实验方案: 我们先在real server上编译安装好http,然后,咋们切换到mysql服务器上安装mysql,在换到http主机上编译php的工作方式基于模块的,再把discuz资源放到http的资源访问目录下,且在双方http主机上布上rsync服务器,双反的主机也要加上inotify来实时关注http访问目录的资源变化,有变化就要数据…

    Linux干货 2015-10-22
  • N26-第十二周

    1、请描述一次完整的http请求处理过程;        1、建立或处理链接:接收请求或拒绝请求        2、接收请求:接收来自于网络的请求报文中对某资源的一次请求的过程;接收请求的方式通常是并发访问响应模型        3、处理请…

    2017-05-14
  • 系统启动流程

    linux系统启动流程 内核的设计结构单内核:linux(线程–lwp轻量级进程)微内核:windows(支持真正意义上的多线程) 单内核:很多功能驱动都集成在一起 微内核:内核很小,功能单一。模块化 linux为了适应众多用户的不同硬件需求,linux内核在设计上采用模块化设计。可以动态加载模块。核心模块:ko 内核所独有的。共享对象:so 红…

    Linux干货 2016-09-19
  • 马哥教育N22期第七周作业

    1、创建一个10G分区,并格式为ext4文件系统; [root@localhost xuc]# cat /proc/partitions  major minor  #blocks  name    8   &…

    Linux干货 2016-10-24
  • linux之网络管理基础

    一.IP分配的概述 公式1 一个网段的主机数=2^主机位数-2 主机ID位数=32-网络ID位数 公式2 网络ID=IP与子网掩码 公式3 划分子网: 一个大网分成若干个小网 网络ID向主机位借位n,子网数2^n 公式4 损失IP-=(子网数2^n-1)*2 合并多个小子网成一个大的超网 如 172.16.0.0-172.31.0.0 就是主机ID向网络ID…

    Linux干货 2016-09-16