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

相关推荐

  • 马哥教育网络班20期+第9周课程练习

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

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

    1、详细描述一次加密通讯的过程,结合图示最佳。 例如:     bob给alice发送一份数据:只能alice看到,不能被篡改。     bob:     首先用单向加密提取数据的特征码,然后用自己的私钥加密这个特征码并放在原有数据的后面;…

    学员作品 2016-09-15
  • 【福利贴-招聘】- 维护工程师

    地点:黄浦–人民广场  职位:技术支持/维护 要求:招1人| 大专| 1-2年 薪资范围: 8-12k 职位职能:技术支持/维护工程师 岗位职责: 1.熟悉Linux及其远程维护; 2.熟练掌握Linux网络安装、日常管理、安全、备份、恢复、故障处理、日志分析等技能; 3.熟悉Web、mysql优化管理、apache等常见的问题及处理 …

    Linux职位 2015-05-14
  • linux操作系统rpm软件包管理

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

    2016-08-22
  • 马哥团队带你领略阿里风景

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

    学员作品 2015-04-29
  • vim编辑器

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

    Linux干货 2016-08-10