马哥教育网络班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 
[email protected]
[email protected]
[email protected]
wangwusf.hiya
huohuo.huo.huo
[email protected]
[root@linux tmp]# egrep  "^[[:alnum:]]+@[[:alnum:]]+\.[[:alnum:]]+$"  ./mail.txt 
[email protected]
[email protected]
[email protected]
[email protected]

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

相关推荐

  • linux 必须掌握的60个命令

    Linux提供了大量的命令,利用它可以有效地完成大量的工 作,如磁盘操作、文件存取、目录操作、进程管理、文件权限设定等。所以,在Linux系统上工作离不开使用系统提供的命令。要想真正理解Linux系统, 就必须从Linux命令学起,通过基础的命令学习可以进一步理解Linux系统。 不同Linux发行版的命令数量不一样,但Linux发行版本最少的命令也有200…

    2017-09-05
  • shell编程

       编程基础   编程基础:       编程:也就是程序+数据           程序编程风格:                  过程式:以指…

    Linux干货 2016-08-15
  • linux 启动管理

    1、Linux系统启动流程:POST 加电自检 — BIOS(Boot Sequence)–>MBR(bootloader,446)(加载前512字节后的驱动程序,进入/boot目录,加载内核)–>Kernel–>initrd–>(系统根路径 /)(ROOTFS)/sbin/…

    Linux干货 2017-09-03
  • 磁盘分区

    磁盘分区 一、分区方式两种 MBR分区不能超过2个T按柱面分区主引导记录存放在,0磁道0扇区 512bytes前446字节存放bootloader (软件程序)64字节:分区表16个字节表示一个有效的分区 故只能分4个主分区。大于4个需要创建扩展分区,并在其中创建逻辑分区。2字节 55AABPT分区GPT:GUID(Globals Unique Identi…

    Linux干货 2016-08-29
  • centos 7.2 安装pyenv多版本管理工具和虚拟环境pyenv-virtualenv

    软件简介: pyenv + pyenv-virtualenv pyenv,是一款特别好用的Python版本管理器,程序员可以建立不同的目录,在不同的目录里分别运行不同版本的Python, 并且互不影响,安装的包也互不影响。github项目地址:https://github.com/yyuu/pyenv pyenv-virtualenv, 是pyenv的一个p…

    Linux干货 2016-07-04
  • Linux的文本处理工具练习题

    练习一:     1、找出ifconfig命令结果中本机的所有IPv4地址 2、查出分区空间使用率的最大百分比值 3、查出用户UID最大值的用户名、UID及shell类型 4、查出/tmp的权限,以数字方式显示  练习二:       1、显示/proc/meminfo文件中以大…

    Linux干货 2016-08-08

评论列表(1条)

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

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