第五周博客作业

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

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

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

[root@localhost ~]# grep -E "[_[:alnum:]]+\(\)" /etc/rc.d/init.d/functions

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

取出基名:
[root@localhost ~]# echo "/etc/rc.d/init.d/functions" | grep -E  -o "[^/]+/?$"
functions
取出路径名:
[root@localhost ~]# echo "/etc/rc.d/init.d/functions" | grep  -o "^.*/"
/etc/rc.d/init.d/

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

[root@localhost ~]# ifconfig | grep -E "\<([0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|2[0-5][0-5])\>"

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

[root@localhost tmp]# ifconfig | grep -E -o "\<((1?[0-9][0-9]?|2[0-4][0-9]|25[0-4])\.){3}(1?[0-9][0-9]?|2[0-4][0-9]|25[0-4])\>"
192.168.0.129
127.0.0.1

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

[root@localhost tmp]# cat mail
1234@qq.com
63737erijrji@yahoo.com.cn
989898#$@hotmail.com
ffd893@abc.org.cn
qq112qq112qq112qq112qq112qq112qq112qq112qq112qq112qq112qq112
[root@localhost tmp]# grep -E "[^[:space:]].*@[^[:space:]].*" mail
1234@qq.com
63737erijrji@yahoo.com.cn
989898#$@hotmail.com
ffd893@abc.org.cn

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

[root@localhost ~]# find /var -user root -a -group mail -ls
50331800    4 drwxrwxr-x   2 root     mail         4096 Dec 20 03:57 /var/spool/mail

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

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

最近3天内曾被访问过的文件或目录

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

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

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

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

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

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

[root@localhost ~]# find /etc/init.d/ -perm -111 -a -perm -002

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

[root@localhost ~]# find /usr -not \( -user root -o -user bin -o -user hadoop \) -ls
135247738    0 drwx------   2 polkitd  root           65 Nov  8 09:13 /usr/share/polkit-1/rules.d
2125565   16 -rwsr-sr-x   1 abrt     abrt        15336 Dec  1  2015 /usr/libexec/abrt-action-install-debuginfo-to-abrt-cache

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

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

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

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

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

(0)
N25_PierceN25_Pierce
上一篇 2017-01-06
下一篇 2017-01-07

相关推荐

  • yum与rpm生产中最频繁使用

    yum 命令 使用方法: yum [选项] [包名称] 常用选项: install #安装软件,后面跟包名称,例如:yum install wget 安装wget软件包list #列出所有软件,一般和grep一起使用,例如:yum list | grep java ,查看所有java安装包,一般情况下不使用search,grep可以更大范围搜索包,例如只记得…

    Linux干货 2017-04-18
  • 概述Windows2003的卷影副本

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://jeffyyko.blog.51cto.com/28563/157940      卷影副本,也就是Volume Shadow Server简单来讲,卷影副本(或称为VSS)可以简单…

    Linux干货 2015-03-25
  • 马哥教育网络班21期+第七周博客作业

    1、创建一个10G分区,并格式为ext4文件系统;    (1) 要求其block大小为2048, 预留空间百分比为2, 卷标为MYDATA, 默认挂载属性包含acl;    (2) 挂载至datamydata目录,要求挂载时禁止程序自动运行,且不更新文件的访问时间戳 [root@ns1 ~]# m…

    Linux干货 2016-08-24
  • 第五周作业:find、cut、grep用法

    第五周作业 1、显示当前系统上root、fedora或user1用户的默认shell; 2、找出/etc/rc.d/init.d/functions文件中某单词后面跟一组小括号的行,形如:hello(); 3、使用echo命令输出一个绝对路径,使用grep取出其基名; 扩展:取出其路径名  4、找出ifconfig命令结果中的1-255之间数字; …

    Linux干货 2016-11-28
  • 马哥网络班第21期-第二周作业毛豆

    1、Linux上的文件管理类命令都有哪些,其常用的使用方法及其相关示例演示。     文件管理命令:cp、mv、rm     cp:      比如:cp -a /etc/*$.d /tmp/magedu.com     mv:      …

    Linux干货 2016-07-22
  • 学习宣言

    不妥协,不气馁,朝着自己的目标前进。

    Linux干货 2016-10-24

评论列表(1条)

  • 马哥教育
    马哥教育 2017-02-17 10:59

    写的很好,排版也很棒,继续加油保持