马哥教育网络班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

相关推荐

  • vim编辑器

      在linux系统中使用文本编辑器来编辑你的配置文件是一件很重要的事。vim是linux最常用的文本编辑器,具有以下优势:所有的linux都内置vi文本编辑器。很多软件都会主动调用vi,如crontab、visudo等. 所以我们必须学好vi,vim分为以下3种模式:   一般模式: 用 vi打开一个文件时,一进入该文件就是一般模式了。…

    Linux干货 2016-06-09
  • 手动创建挂载交换分区

    SWAP分区 SWAP [root@cloud ~]# fdisk /dev/sdb Command (m for help): d Selected partition 1 Command (m for help): w The…

    Linux干货 2016-06-09
  • 是否

    是否

    Linux干货 2016-08-22
  • Gay Video Chat Sites – Personals

    Bromodates Men Seeking Men eHarmony.com Adam4Adam.com FabGuys.com Grindr Taimi GayCupid.com Scruff Hornet Gaydar Bromodates – Popular gay hookup app internationally You will …

    Linux干货 2023-02-21
  • N22-第十四周作业

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

    Linux干货 2017-03-15
  • 10 文本处理のsed狗带

    sed 介绍 工作原理 语法 参数选项:-n, -e, -r, -f, -i 地址定界 编辑命令 查找替换 空间操作 练习 参考文档 sed介绍 sed是一个(stream editor)。         1) :使用sed只能在命令行下输入编辑命令来编辑文…

    Linux干货 2016-08-12

评论列表(1条)

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

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