N26-第五周博客

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

[root@localhost ~]# grep "^[[:space:]].*$" /boot/grub/grub.conf

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

[root@localhost ~]# grep "^#[[:space:]]\+[^[:space:]].*" /etc/rc.d/rc.sysinit 

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

[root@localhost ~]# netstat -tan | grep "LISTEN[[:space:]]\+$"

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

[root@localhost ~]# grep -E "^([^:]+).*\1$" /etc/passwd

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

[root@localhost ~]# grep -E "^(root|fedora|user1).*" /etc/passwd | cut -d: -f1,7

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

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

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

 [root@localhost log]# echo /etc/rc.d/init.d/funct.ions | grep -o "[^/]*$"
[root@localhost log]# echo "/etc/rc.d/init.d/funct.ions" | grep -o "/.*/" | grep -o "/.*[^/]"

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

[root@localhost log]# ifconfig | grep  --color=auto -E "([0-9]|[1-9][0-9]|[1-2][0-2][0-9])"

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

ifconfig | grep -o -E "(([0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[0-9][0-9]|1[0-9]

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

[root@localhost log]# grep -E "^[[:alnum:]]_*[[:alnum:]]*@[[:alnum:]]+.[[:alpha:]]"

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

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

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

[root@localhost log]# find / -nouser -a -nogroup -ls
[root@localhost log]# find / -nouser -a -nogroup -a -atime -3    

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

[root@localhost log]# find /etc -perm -222 -ls

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

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

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

[root@localhost log]# find /etc/init.d -type f -perm -113

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

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

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

[root@localhost log]# find /etc/ -type f -perm /222  -ls

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

[root@localhost log]# find /etc -type f -atime -7 -not \( -user root -o -user hadoop \)

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

(0)
youngferyoungfer
上一篇 2017-02-10 15:39
下一篇 2017-02-10 20:40

相关推荐

  • 聊聊CentOS6的启动过程

    前言:     作为一个合格的运维人员,系统的启动过程我们需要牢记在心,此文不深入探讨,只求大致理解CentOS6的启动过程。 一张图带你了解CentOS6的启动过程 注意:图片放大查看效果更佳 上图各阶段详解 POST:计算机开机时BIOS对其各硬件的简单测试,测试各硬件的完整性 BootSqunce:加电自检后根据…

    Linux干货 2016-03-14
  • 关于网络配置管理

                                                      &nbsp…

    系统运维 2016-09-07
  • GOPS 2016全球运维大会 上海站

    GOPS 2016全球运维大会 • 上海站已经圆满落幕,最新GOPS大会推荐:GOPS2017全球运维大会 • 深圳站 基本信息: GOPS2017全球运维大会 • 深圳站 时间:2017-04-21 08:00:00 至 2017-04-22 18:00:00结束 地点:深圳    会议规模:5000人 会议详情:http://www.…

    系统运维 2016-09-07
  • vim编辑器的用法

    vim编辑器的用法 1、vi的基本概念     vi可以分为三种模式,分别是命令模式(command mode)、输入模式(Insert mode)和末行模式(last line mode),各模式的功能如下:     1) 命令行模式command mode)         …

    Linux干货 2015-09-14
  • 第一周的学习总结

       本人是Linux 小白,0基础。加入马帮开始Linux之旅。由于完全不懂Linux,所以在学习的过程中,每课都要看上2遍。接下来说说我第一周所学的内容。 首先是了解到了计算机基础知识,计算机的组成部分、CPU架构类型、其他外围设备。 操作系统基础知识进程管理、内存管理、网络管理、驱动管理、安全管理等。 Linux的起源、发行版以及构…

    Linux干货 2016-02-28

评论列表(1条)

  • 马哥教育
    马哥教育 2017-03-30 14:32

    find grep结合正则将会有无穷的威力,从作业中看出掌握了非常扎实,继续加油。