马哥教育网络班21期+第五周课程练习

1、显示/boot/grub/grub.conf中以至少一个空白字符开头的行;

~]# egrep ^[[:space:]] /boot/grub/grub.conf

2、显示/etc/rc.d/rc.sysinit文件中以#开头,后面跟至少一个空白字符,而后又有至少一个非空白字符的行;

~]# egrep ^#[[:space:]]+[^[:space:]]+ /etc/rc.d/rc.sysinit

3、打出netstat -tan命令执行结果中以‘LISTEN’,后或跟空白字符结尾的行;

~]# netstat -tan | egrep "LISTEN[[:space:]]+"

4、添加用户bash, testbash, basher, nologin (此一个用户的shell为/sbin/nologin),而后找出当前系统上其用户名和默认shell相同的用户的信息;

#!/bin/bash
#
for i in bash testbash basher nologin;do
      if ! id $i &> /dev/null;then
          if [ $i == nologin ];then
          useradd -s /sbin/nologin $i
          else
          useradd $i
          fi
     else
        echo "$i exist"
          if [ $i == nologin ];then
            userdel -r $i
            useradd -s /sbin/nologin $i
            echo "$i reinstitute"
          fi
       fi

done
  egrep "^([[:alnum:]]+\>).*\1$"  /etc/passwd

5、显示当前系统上root、fedora或user1用户的默认shell;

~]# egrep "^root\>|^fedora\>|^user1\>" /etc/passwd | cut -d: -f7

6、找出/etc/rc.d/init.d/functions文件中某单词后面跟一组小括号的行,形如:hello();

~]# grep  "\<[[:alpha:]]\+()" /etc/init.d/functions

7、使用echo命令输出一个绝对路径,使用grep取出其基名;

    扩展:取出其路径名

取其基名
~]#  echo /etc/rc.d/rc3.d/K01smartd | grep -o "[^/]\+$"
取其路径名
~]# echo /etc/rc.d/rc3.d/K01smartd | grep -o "[/][^/]\+.*[/]"|cut -d"/" -f1-4

8、找出ifconfig命令结果中的1-255之间数字;

~]# ifconfig |egrep  "\<[1-9][0-9]\>|\<[0-9]\>|\<[1][0-9][0-9]\>|\<[2][0-4][0-9]\>|\<[2][5][0-5]\>"

9、挑战题:写一个模式,能匹配合理的IP地址;

~]# ifconfig |egrep -o "[1-2]?[0-9]{,2}\.[1-2]?[0-9]{,2}\.[1-2]?[0-9]{,2}\.[1-2]?[0-9]{,2}"
192.168.0.108
192.168.0.255
255.255.255.0
192.168.160.160
192.168.160.255
255.255.255.0
127.0.0.1
255.0.0.0

10、挑战题:写一个模式,能匹配出所有的邮件地址;

[root@linux tmp]# cat mail.txt 
zhangsan@163.com
lisi123@123.com
123456@yahoo.com
wangwusf.hiya
huohuo.huo.huo
huo99@mage.com
[root@linux tmp]# egrep  "^[[:alnum:]]+@[[:alnum:]]+\.[[:alnum:]]+$"  ./mail.txt 
zhangsan@163.com
lisi123@123.com
123456@yahoo.com
huo99@mage.com

11、查找/var目录下属主为root,且属组为mail的所有文件或目录

~]# find /var -user root -a -group mail -ls

12、查找当前系统上没有属主或属组的文件;

[root@linux tmp]# find / -type f -nouser -a -nogroup -ls 
261162    0 -rw-rw-r--   1 3007     3007            0 Aug  6 20:52 /tmp/test.txt
261169    0 -rw-rw-r--   1 3007     3007            0 Aug  6 20:52 /tmp/kkk

查找当前系统上没有属主或属组,且最近3天内曾被访问过的文件或目录;

[root@linux tmp]# find / -nouser -a -nogroup -a -atime -3
/tmp/test.txt
/tmp/kkk

13、查找/etc目录下所有用户都有写权限的文件;

~]# find / -type f -perm -222 -ls

14、查找/etc目录下大于1M,且类型为普通文件的所有文件

[root@linux ~]# find /etc -type f -size +1M |xargs ls -lh
-rw-r--r--. 1 root root 1.3M Aug  4 22:22 /etc/gconf/gconf.xml.defaults/%gconf-tree.xml
-rw-r--r--. 1 root root 1.1M Apr 24  2015 /etc/pki/tls/certs/ca-bundle.trust.crt
-rw-r--r--. 1 root root 8.0M Aug  4 08:54 /etc/selinux/targeted/modules/active/policy.kern
-rw-r--r--. 1 root root 8.0M Aug  4 08:54 /etc/selinux/targeted/policy/policy.24

15、查找/etc/init.d/目录下,所有用户都有执行权限,且其它用户有写权限的文件;

~]# find /etc/init.d/ -perm -113 -ls
393283    0 -rwxr-xrwx   1 root     root            0 Aug  6 21:15 /etc/init.d/test.txt

16、查找/usr目录下不属于root、bin或hadoop的文件

~]# ~]# find /usr  -not -user root -a -not -user bin -a -not -user hadoop -ls

17、查找/etc/目录下至少有一类用户没有写权限的文件;

~]# find /etc -not -perm -222 -ls

18、查找/etc目录下最近一周内其内容被修改过,且不属于root或hadoop的文件;

~]# find /etc -mtime -7 -a -not -user root -not -user hadoop

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

(0)
上一篇 2016-08-08 16:13
下一篇 2016-08-08 16:13

相关推荐

  • N21天天第十二周课程练习

    1、请描述一次完整的http请求处理过程; 1、建立TCP连接 2、Web浏览器向Web服务器发送请求 3、Web浏览器发送请求头信息   建立连接后,客户机发送一个请求给服务器,请求方式的格式为:统一资源标识符(URL)、协议版本号,后边是MIME   信息包括请求修饰符、客户机信息和可能的内容 4、Web服务器应答…

    Linux干货 2016-10-31
  • Linux基础:计算机的组成及其功能

    1. 描述计算机的组成及其功能。
    2. 按系列罗列Linux的发行版,并描述不同发行版之间的联系与区别。
    3. 描述Linux的哲学思想,按照自己的理解对其解释性描述。
    4. 说明Linux系统上命令的使用格式;详细介绍ifconfig、echo、tty、startx、export、pwd、history、shutdown、poweroff、reboot、hwclock、date等命令使用,配合相应实例阐述。
    5. 如何获取帮助信息,描述man文档章节划分。
    6. 罗列发行版基础目录名称命名法则及功用规定。

    2017-12-07
  • linux 下的文件压缩与解压

    文件压缩 压缩原理:把文件的二进制代码压缩,把相邻的0,1代码减少,比如有000000,可以把它变成6个0 的写法60,来减少该文件的空间。 目的:时间换空间,cpu时间–>空间 压缩文件工具:    compress|uncompress 压缩后的文件.z    gzip|gunzip  …

    Linux干货 2016-08-21
  • 马哥教育网络班20期+第5周课程练习

    1、显示/boot/grub/grub.conf中至少一个空白字符开头的行 [root@localhost ~]# grep "^[[:space:]]\+.*" /boot/grub2/grub.cfg 2、显示/etc/rc.d/rc.sysinit文件中以#开头,后面跟至少一个空白字符,而后又有至少一个非空白字符的行; [root@…

    Linux干货 2016-08-15
  • Nginx 功能概述与基础应用!

           本篇博客主要有三个部分组成,目的在于让大家了解ningx的主要功用及作为web server的基础配置;通过本篇博客能够让您对nginx理解更加深入,以便于更好的使用它!                  …

    2017-05-14
  • sed与vim相关练习

    sed 练习 以行为单位的新增/删除功能 1将 /etc/passwd 的内容列出并且打印行号,同时,请将第 2~5 行删除! 2在第二行后(亦即是加在第三行)加上“the is xing line?”字样! 3在第二行前(亦即是加在第而行)加上“the is xing line?”字样! 4在第二行后面加入两行字,例如“the is xing line &…

    Linux干货 2016-08-10

评论列表(1条)

  • 马哥教育
    马哥教育 2016-08-08 17:02

    写的很好,排版也很棒,加油,匹配ip地址不对