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
下一篇 2016-08-08

相关推荐

  • 马哥linuxYY讲师征集令

    马哥linuxYY讲师征集令 有胆你就来   想在马帮群雄面前一展身手,分享你的工作经验和感悟吗?       敢在众人面前畅所欲言,展现实力,增加个人影响力吗?       快来加入马哥教育YY讲师团吧,带上你的分享主…

    2015-09-09
  • 马哥教育网络第20期-第一周作业

    第一周博客作业1、 描述计算机的组成及其功能。 运算器、控制器、存储器、输入设备、输出设备运算器、控制器 :cpu 运算和逻辑计算存储器:缓存和保存数据输入设备、输出设备:用户和计算机交互设备和界面 2、 按系列罗列Linux的发行版,并描述不同发行版之间的联系与区别。 Slackware系列: suse   opensuse debian系列: …

    学员作品 2016-06-23
  • 马哥教育网络班20期+第9周博客作业

    1、写一个脚本,判断当前系统上所有用户的shell是否为可登录shell(即用户的shell不是/sbin/nologin); 分别这两类用户的个数;通过字符串比较来实现;     #!bin/bash     export clogin=0   &…

    学员作品 2016-09-10
  • vim编辑器

    一、vim简介    vi: Visual Interface,文本编辑器     文本: ASCII, Unicode     文本编辑种类:         行编辑器: sed…

    Linux干货 2016-08-10
  • 关于文本处理工具之SED

                                                      &nbsp…

    学员作品 2016-08-10
  • 文本处理工具sed及文本编辑器vim课程作业

    文本处理工具sed课程作业     1、删除/etc/grub2.conf文件中所有以空白开头的行行首的空白字符         sed -n 's@^[[:space:]]\+@@p' /etc/grub2.cfg &…

    学员作品 2016-08-10