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

相关推荐

  • 设计模式 ( 十八 ) 策略模式Strategy(对象行为型)

    设计模式 ( 十八 ) 策略模式Strategy(对象行为型) 1.概述         在软件开发中也常常遇到类似的情况,实现某一个功能有多种算法或者策略,我们可以根据环境或者条件的不同选择不同的算法或者策略来完成该功能。如查找、排序等,一种常用的方法是硬编码(Hard Coding)在一个类中,如需要提供多种查找算…

    Linux干货 2015-07-28
  • linux系统监控 sar命令详解

    sar(System Activity Reporter系统活动情况报告)是目前 Linux 上最为全面的系统性能分析工具之一,可以从多方面对系统的活动进行报告, 包括:文件的读写情况、系统调用的使用情况、磁盘I/O、CPU效率、内存使用状况、进程活动及IPC有关的活动等。 本文主要以CentOS 6.3 x64系统为例,介绍s…

    Linux干货 2015-06-17
  • varnish原理及配置事例

    Varnish是一款高性能的开源HTTP加速器(其实就是带缓存的反向代理服务),可以把http响应内容缓存到内存或文件中,从而提高web服务器响应速度。与传统的 squid 相比,varnish 具有性能更高、速度更快、管理更加方便等诸多优点,很多大型的网站都开始尝试使用 varnish 来替换 squid,这些都促进 varnish 迅速发展起来 Varn…

    Linux干货 2015-12-06
  • Linux运维利器之ClusterShell

    Via:http://blogread.cn/it/article/4573?f=wb 如果你有若干台数据库服务器,突然你想知道它们当前的即时负载情况,你会怎么办?挨个登录上去uptime一下?感觉有点傻,写个shell?浪费时间,直接用ClusterShell吧! ClusterShell的安装与配置     Clu…

    Linux干货 2015-05-12
  • HipHop PHP实战(详解web运行模式)

    Note: These code examples assume the HipHop compiler is fully built. 1 . Setting Up Your Environment (构建环境) To get started, you need to configure two environment variables. cd…

    Linux干货 2015-04-10
  • Linux文本搜索工具grep

    Linux文本搜索工具grep Linux文本搜索工具grep grep 基本正则表达式 egrep 扩展正则表达式 fgrep 简介 grep(全称Globally search a Regular Expression and Print,全面搜索正则表达式并把行打印出来)是一种强大的文本搜索工具,根据用户指定的“模式(pattern)”对目标文本进行匹…

    2016-04-05

评论列表(1条)

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

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