8月5日课堂及课后作业

课堂作业

1.找出ifconfig命令结果中的IP地址

[root@localhost ~]# ifconfig |head -2|grep "inet" |tr " " ":"|cut -d: -f13

8月5日课堂及课后作业

2、找出df中磁盘利用率的数

[root@localhost ~]# df |tail -5|tr ' ' ':' |tr -s :|cut -d: -f5 |tr "%" " "

8月5日课堂及课后作业

简便方法: [root@localhost ~]# df |tail -5 |tr -s " "|cut -d" " -f5 |tr -d %

注意:tr -s 是去掉相同的 tr -d 是删除 tr -cd删除取反的(忘记了,再记)

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

[root@localhost ~]# ifconfig |tr -cs '[0-9].' '\n' |sort -ut '.' -k3n

8月5日课堂及课后作业

4、查处分区空间使用率的最大百分比值

[root@localhost ~]# df |tr -s " "|tr " " ":"|cut -d: -f5|tr -d %|sort -n|tail -1

8月5日课堂及课后作业

5、查处用户uid最大值的用户名、uid及shell类型

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

8月5日课堂及课后作业

6、查处/tmp的权限,以数字方式显示

[root@localhost ~]# stat /tmp|grep "Uid"|cut -d: -f2 |tr -cs [0-9] ' '

8月5日课堂及课后作业

方法二:[root@localhost ~]# stat /tmp|grep "Uid"|tr -cs [0-9] ' '|cut -d" " -f2

7、显示/proc/meminfo文件中以大小s开头的行(两种方法)

[root@localhost ~]# grep -i '^s.*' /proc/meminfo 

[root@localhost ~]# grep  '^[Ss].*' /proc/meminfo

8月5日课堂及课后作业

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

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

8月5日课堂及课后作业

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

[root@localhost ~]# getent passwd|grep '^rpc\>' |cut -d: -f7

8月5日课堂及课后作业

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

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

8月5日课堂及课后作业

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

[root@localhost ~]# grep "^[[:space:]]\+[^[:space:]].*" /etc/grub.conf

8月5日课堂及课后作业

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

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

8月5日课堂及课后作业

13、添加用户bash,testbash,basher,nologin(shell为/sbin/nologin)。然后找出/etc/passwd文件中用户名同shell名相同的行

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

8月5日课堂及课后作业

14、显示三个用户root,mage,wang的uid和默认shell

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

8月5日课堂及课后作业

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

[root@localhost ~]# egrep  "^[[:alpha:]_]*\(\)" /etc/rc.d/init.d/functions

8月5日课堂及课后作业

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

[root@localhost ~]# echo " /etc/rc.d/init.d/functions" |egrep -o "[^/]+/?$"

8月5日课堂及课后作业

17、使用egrep取出/etc/ec.d/init.d/functions的目录名

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

8月5日课堂及课后作业

18、统计以root身份登录的每个进程主机ip地址的登录次数

[root@localhost ~]# last |egrep -o "^root\>.*([[:digit:]]\.){3}[[:digit:]]" |tr -s '' |cut -d ' ' -f3|sort |uniq -c

19、利用扩展正则表达式分别表示0-9,10-99,100-199,200-249,250-255,显示ifconfig命令结果中所有ipv4地址

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

8月5日课堂及课后作业

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

[root@localhost ~]# cat /etc/init.d/functions |tr -cs '[:alpha:]' "\n" |sort|uniq -c|sort -nr

8月5日课堂及课后作业

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

[root@localhost ~]# echo "/etc/rc.d/init.d/functions/" |sed 's@[^/]\+/\?$@@'

8月5日课堂及课后作业

22、正则表达式表示身份证(后续几题暂时不会)

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

(1)
1515218807015152188070
上一篇 2016-08-08 16:15
下一篇 2016-08-08 16:15

相关推荐

  • 第六次作业

    1 、取本机ip地址 Centos6.8 ifconfig | head -2|tail -1|cut -d: -f2|cut -d" " -f1 ifconfig | head -2|tail -1|cut&…

    学员作品 2016-08-10
  • 文本处理工具系列(一):文本的查看、分析、统计和文本过滤工具

    1、文本的查看、分析和统计工具    <1>文本查看工具  cat tac rev more less head  tail  cut  paste       cat         -A:显示所…

    学员作品 2016-08-08
  • sed和vim的爱恨纠缠

    处理文本的工具sed sed是一种流编辑器,它一次处理一行内容。处理时,把当前处理的行存储在临时缓冲区中,称为“模式空间”(patternspace),接着用sed命令处理缓冲区中的内容,处理完成后,把缓冲区的内容送往屏幕。接着处理下一行,这样不断重复,直到文件末尾。文件内容并没有改变,除非你使用重定向存储输出。Sed主要用来自动编辑一个或多个文件,简化对文…

    2016-08-10
  • Linux普通权限及特殊权限讲解

    1.文件权限 文件权限主要是针对三类对象进行定义的:                          &nb…

    学员作品 2016-08-05
  • Selinux的基本命令及练习

    配置SELinux 相关命令:       getenforce: 获取selinux当前状态       sestatus :查看selinux状态      &nbs…

    学员作品 2016-09-19
  • 马哥教育网络班21期-第七周课程练习

    第七周 1、创建一个10G分区,并格式为ext4文件系统;    (1) 要求其block大小为2048, 预留空间百分比为2, 卷标为MYDATA, 默认挂载属性包含acl;    (2) 挂载至/data/mydata目录,要求挂载时禁止程序自动…

    学员作品 2016-08-29