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

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

[root@localhost ~]# grep "^[[:space:]]\{1,\}" /boot/grub/grub.conf

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

[root@localhost ~]# grep "^#[[:space:]]\{1,\}[^[:space:]]\{1,\}" /etc/rc.d/rc.sysinit

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

[root@localhost ~]# netstat -tan | egrep "(\<LISTEN\>|[[:space:]])$"

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

#!/bin/bash
#

for user in bash testbash basher nologin;do
    id $user &> null
    if [ $? -eq 0];then
        echo "$user is exist"
    else
        if [ $user != nologin ];then
                useradd $user
        else
                useradd -s /sbin/nologin $user
        fi
    fi
done

grep "^\(\<[[:alnum:]]\+\>\):.*\1$" /etc/passwd | cut -d: -f1

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

[root@localhost ~]# for user in root fedora user1;do grep "^$user" /etc/passwd | cut -d: -f1,7;done

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

[root@localhost ~]# grep "\<[[:alpha:]]\+\>()" /etc/rc.d/init.d/functions

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

    扩展:取出其路径名

[root@localhost games]# echo /usr/local/ga1mes | grep -o "\<[[:alnum:]]\+\>$"  #取基名
[root@localhost games]# echo "/usr/local/games" | grep -o "^\/.*\/"  #取路径名

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

[root@localhost games]# ifconfig eth0 | egrep -o "\<[1-9]\>|\<[1-9][0-9]\>|\<1[0-9][0-9]\>|\<2[0-4][0-9]\>|25[0-5]"

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

[root@localhost ~]# ifconfig eth0 | egrep -o "(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])"

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

[root@localhost ~]# echo la1y_123@126x.com | grep "[[:alnum:]_]\+@[[:alnum:]]\+\.[[:alpha:]]\{2,\}"

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

[root@localhost games]# find /var -user root -group mail

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

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

a. [root@localhost ~]# find / -nouser -o -nogroup
b. [root@localhost ~]# find / -nouser -o -nogroup -atime -3

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

[root@localhost ~]# find /etc -perm  -2

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

[root@localhost ~]# find /etc -size +1M -type f

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

[root@localhost ~]# find /etc/init.d/ -perm -113

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

[root@localhost ~]# find /usr -not \( -user root -o -user bin -o -user hadoop \)

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

[root@localhost ~]# find /etc/ -not  -perm /2

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

[root@localhost ~]# find /etc/ -mtime -7 -not \( -user root -o -user hadoop \)

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

(0)
Net21_木头Net21_木头
上一篇 2016-08-08
下一篇 2016-08-08

相关推荐

  • 用户与用户组

    用户与组常见命令与用法

    Linux干货 2017-11-18
  • LVS的工作原理

    LB Load Balancing:解决方案 硬件: F5 BIG-IP 思杰 Citrix Netscaler A10 A10 Array  Redware 软件:lvs  linux Virtual Server 作者章文嵩博士 ipvs相当于netfilter,工作在内核中,将用户转发    框架,需要依赖以规则…

    Linux干货 2016-12-07
  • raid5创建

    创建分区并改类型 创建raid5   创建把文件系统 生成配置文件    

    2017-12-17
  • 第五周练习

    1.显示当前系统上root,fedora或user1用户的默认shell         # cat /etc/passwd | cut -d: -f1,7 | grep -E "(fedora|root|user1)" 2.找出/etc/rc.d/init.…

    Linux干货 2016-11-26
  • Heartbeat-Gui V2 实现HA LAMP 搭建wordpress博客

    环境:           N F S: 172.16.0.3 (OS CentOS 7)           node1:172.16.0.5 (OS CentOS 6.7)    &nb…

    Linux干货 2016-10-27
  • iptables/netfilter进阶

      在上一章当中我们介绍了iptables的介绍以及它的基本使用,下面我们开始介绍iptables的命令用法以及iptables是如何工作的。 1、回顾 2、iptables相关命令 1、回顾   我们回顾一下上一章节的内容,在上一章节中我们讲述的是iptables的基本概念以及命令格式,同时讲述规则链与表的概念,那么…

    Linux干货 2017-02-03

评论列表(1条)

  • 马哥教育
    马哥教育 2016-08-17 15:37

    写的很好,排版也很棒,加油