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

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

	[root@localhost ~]# awk -F: '{print $1,$7}' /etc/passwd| egrep "^\<(root|fedora|user1)\>" 
	root /bin/bash
	user1 /bin/bash
	fedora /bin/bash

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

	[root@localhost ~]# grep '\<[a-z]\+\>()' /etc/rc.d/init.d/functions 

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

	[root@localhost tmp]# echo '/etc/fstab' |egrep -o '[^/]+/?$'

    扩展:取出其路径名

	echo '/etc/fstab' |egrep -o '^/.*/' 

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

	[root@localhost tmp]# ifconfig |egrep -o '\<([1-9]|[1-9][0-9]|[1|2][1-9][0-9])\>'

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

	[root@localhost tmp]# ifconfig |egrep -o "[1-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"

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

	[root@localhost tmp]#  egrep -o "[[:alnum:]]+@[[:alnum:]]+.[[:alnum:]]+"  test 
	abc@tom.com
	145@163.com
	565@qq.com
	bc@qqx.com

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

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

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

	[root@localhost tmp]# find / \( -nouser -o -nogroup \) -type f

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

	[root@localhost tmp]# find / \( -nouser -o -nogroup \) -atime -3

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

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

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

	[root@localhost tmp]# find /etc -size +1M -type f -exec ls -lh {} \;

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

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

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

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

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

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

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

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

原创文章,作者:N22_上海_长清,如若转载,请注明出处:http://www.178linux.com/45304

(0)
N22_上海_长清N22_上海_长清
上一篇 2016-09-15 22:21
下一篇 2016-09-15 22:21

相关推荐

  • 编译内核

     编译内核: 步骤: (1) 准备好开发环境 (2) 获取目标主机上硬件设备的相关信息 (3) 获取目标主机系统功能的相关信息         例如:需要启用相应的文件系统 (4) 获取内核源代码包 www.kernel.org  

    Linux干货 2018-01-01
  • Shell脚本中循环浅析

    在shell脚本中,循环是很重要的一环。循环可以不断的执行某个程序段落,直到用户设置的条件达成为止。在shell中,除了这种依据判断时达成与否的不定循环之外,还有另外一种已经固定要跑多少次的循环,可称之为固定循环。下面,我们主要对for,while,until三种循环做一下介绍。   一、for循环 For循环是给定变量列表的固定次数循环,其执行机…

    Linux干货 2016-08-21
  • Linux逻辑卷LVM实现

    Linux逻辑卷LVM实现 背景: 在学习Linux中,学习到了逻辑卷LVM,发现LVM是个十分好用的一个技术,可以多个硬盘合并在一起使用,同时还可以动态的增加和减少。在这里将Linux逻辑卷的具体实现记录下来。 介绍: 逻辑卷LVM:Logica Volum Manager,它是Linux环境下对磁盘分区进行管理的一种机制,普通的磁盘分区管理方式在逻辑分区…

    2017-08-12
  • Linux高级文件系统管理

                                          &n…

    系统运维 2016-09-06
  • Linux 基础(7)——文本处理工具

    cat  tac  rev  more  less           head  tail cut  paste  wc               &nbs…

    2017-07-29
  • n25第二周

    linux文件管理类命令     mkdir,rmdir,cp,mv,rm,chwon,chmod     1.mkdir->make directories(创建目录)     用法:    &nbsp…

    Linux干货 2016-12-11