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

相关推荐

  • 马哥团队带你领略阿里风景

    马哥团队带你揭秘互联网巨头公司—阿里巴巴 继马哥团队腾讯一行之后,4月中旬我们又来到了坐落于杭州的另一个互联网巨头公司。 波涛万里长江水,带你入杭州。 真情伴你走,春色为你留。 西湖烟水茫茫,百顷风潭,十里荷香。 风景甚好,怎能不去杭州的阿里巴巴转转呢? 带着“淡妆”,走,跟着我们前行…… 马哥更是笑道:“我们这次来是和马云谈合作的!让我们培训出来的更多同学…

    学员作品 2015-04-29
  • vim 作业

    4、如何设置tab缩进为4个字符?  vi/vim中,可以通过在~/.vimrc中添加set ts=4 执行source ~/.vimrc 重读配置文件 5、复制/etc/rc.d/init.d/functions文件至/tmp目录;替换/tmp/functions文件中的/etc/sysconfig/init为/var/log; 拓展模式下: &…

    学员作品 2016-08-15
  • linux操作系统rpm软件包管理

    软件包管理 软件包运行环境: API:Application Programming Interface     使用标准:POSIX:     源代码运行步骤:预处理(如处理注释)—>编译成汇编代码—>链接其他库文件 ABI:applicatio…

    2016-08-22
  • 马哥linux运维雄鹰社团第一届博客大赛

    能登上金字塔塔顶的只有鹰和蜗牛 世界那么大,我想去看看!我带着你,你带着钱,想去哪去哪!来马哥教育,夺博客大赛最佳,实现人生巅峰! 面对现状你该如何抉择 亲爱的学员们,自己一个人学习是否缺乏动力呢? 是否不知道其他人的学习进度参考,而不能及时激励自己奋进呢? 是否每每懊悔自己没有利用好时间,而导致学习进度大幅落下呢? 马哥linux为你点亮通向远方的一盏灯 …

    2015-05-20
  • sed 流编辑器 练习

    8-9 sed 练习 1、删除/etc/grub2.conf文件中所有以空白开头的行行首的 空白字符 sed 's@^[[:space:]]@@g' /etc/grub2.conf  2、删除/etc/fstab文件中所有以#开头,后面至少跟一个空 白字符的行的行首的#和空白字符 sed 's@^#[[:space:]]\{1…

    学员作品 2016-08-10
  • 马哥教育网络班20期-第九周课程作业

    1、写一个脚本,判断当前系统上所有用户的shell是否为可登录shell(即用户的shell不是/sbin/nologin);分别这两类用户的个数;通过字符串比较来实现; #!/bin/bash nologinsum=$(awk -F: '$NF~/\/sbin\/nologin$/{print $1}'&n…

    学员作品 2016-09-08