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

相关推荐

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

    1.描述计算机的组成及其功能 计算机的组成及各功能:  计算机主要由硬件、操作系统、软件三大部分组成 硬件 :主要由五部分组成 :运算器:主要是做数据运算              控制器:控制计算机各部件的协调和寻址操作         …

    Linux干货 2016-08-15
  • nginx状态监控

    通过查看Nginx的并发连接,我们可以更清除的知道网站的负载情况。Nginx并发查看有两种方法(之所以这么说,是因为笔者只知道两种),一种是通过web界面,一种是通过命令,web查看要比命令查看显示的结果精确一些。下面介绍这两种查看方法 No1、通过浏览器查看 通过web界面查看时Nginx需要开启status模块,也就是安装Nginx时加上 &n…

    Linux干货 2016-10-19
  • awk 的相关知识

    awk 介绍,基本用法,变量,格式化,操作符,条件判断,循环,数组,函数等

    2018-01-01
  • 马哥教育网络班22期+第4周课程练习

    1、复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其它用户均没有任何访问权限。 [root@localhost ~]# cp -r /etc/skel /home/tuser1 [root@localhost ~]# chmod&nb…

    Linux干货 2016-09-05
  • ~~ 1;列出当前系统上所有已经登录的用户的用户名,注意:同一用户登录多次,则只显示 一次即可。 # who | cut -d" " -f 1 | sort -u 2;取出最后登录到当前系统的用户的相关信息 # id $(who | tail -1 |cut -d" " -f 1) # last | head -1 3…

    Linux干货 2017-01-03
  • LVS入门

    随着互联网进入寻常百姓家,网络流量愈来愈大,大规模的网路访问如果都使用一个服务器提供服务,那么网络通讯注定会拥堵不堪。为了解决这些问题,达到使网络流量均衡地分散到各个服务器上的目的,一些技术大牛发明了LVS负载均衡技术。   LVS简介   LVS(Linux Virtual Server)即为Linux虚拟服务器,使由章文嵩博士主导开发…

    Linux干货 2017-05-09

评论列表(1条)

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

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