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

相关推荐

  • vim文本处理工具

    vim编辑器     1、文本的编辑器的种类:         行编辑器:所谓的行编辑器是指一行一行来编辑处理的工具,如sed         全屏编辑器:编辑空间占据整个屏幕,如…

    学员作品 2016-08-10
  • Linux 用户,组和用户权限的使用

    echo -e "Hello,I am 'whoami',the system version is here,please helcheck ist  thanks! \n'lsb_release'"| mail -s 'help'root cmd1 |cmd 2 cma1 2&…

    2016-08-05
  • 关于shell变量计算中单中括号与双中括号、单引号与双引号的一些看法

      单中括号是比较基本的变量计算及数值比较的方法,一般情况下已经足够使用;双中括号是扩展的数值比较方法,里面的数值计算也相对来说复杂些。这里我推荐大家平常工作中使用单中括号即可,满足日常的工作,不做运维开发的话,双括号方面涉及不多。   这里我还得提下单括号与双括号,这里也是我经常混淆的地方,其实理解了也就轻松多了。单括号是对一段比较长的…

    学员作品 2016-08-15
  • 马哥教育网络20期+第十四周课程练习

    系统的INPUT和OUTPUT默认策略为DROP; # iptables -P INPUT DROP # iptables -P OUTPUT DROP 1、限制本地主机的web服务器在周一不允许访问;新请求的速率不能超过100个每秒;web服务器包含了admin字符串的页面不允…

    学员作品 2016-11-14
  • -pxe

    一. BootStraping(OS install): 1. pxe:preboot excution environment , 即预启动执行环境,由intel开发,可实现无人值守自动安装操作系统 ( 依赖于dhcp (dhcpd )服务器与 ftp(lftp) 服务器) 2. pxe 自动化系统安装的流程: 1. client 从pxe网卡模式启动, …

    2016-11-18
  • Linux进程查看和管理及作业控制

    在linux系统中,内核的功用有:进程管理、文件系统、网络功能、内存管理、驱动程序、安全功能等,在这众多的模块中,进程管理是相对重要的一环,即使不像文件系统和网络功能那么复杂。在进程管理中,内核对进程的创建、切换、撤销和调度都有很详细的定义。  1、进程类型     守护进程:在系统引导过程中启动的进程,跟终端无关的进…

    学员作品 2016-11-14