N22-第五周博客作业

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

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

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

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

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

[root@bogon ~]# echo /etc/answer/test/  | grep -E -o  "[^/]+/?$"
[root@bogon ~]# echo /etc/answer/test/  | grep -o  "[^/]\+\/\?$"

扩展:取出其路径名

[root@bogon ~]# echo /etc/answer/test/ | sed 's@[^/]\+/\?$@@'/etc/answer/

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

[root@bogon ~]# ifconfig | grep -E -o "[1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]"

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

[root@bogon ~]# ifconfig | grep -E -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])"
172.16.13.153
255.255.255.0
172.16.13.255
127.0.0.1
255.0.0.0
192.168.122.1
255.255.255.0
192.168.122.255

“.” 需要加转义符,不然不会精确匹配

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

[root@bogon ~]# grep  -E  -o "[[:alnum:]]+\@[[:alnum:]]+\.[[:alnum:]]"

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

[root@bogon ~]# find /var  -user root -a -group mail
/var/spool/mail
[root@bogon ~]# ls -ld /var/spool/maild
rwxrwxr-x. 2 root mail 30 9月  24 13:04 /var/spool/mail

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

[root@bogon ~]# find / -nouser -o  -nogroup

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

[root@bogon ~]# find / -nouser -o  -nogroup -a -atime -3

-3:三天内 , 3:3-4的那一天,+3:大于等于4天

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

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

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

[root@bogon ~]# find /etc -size +1M -type f -exec ls -lh '{}' \;
-rw-r--r--. 1 root root 3.7M 11月 21 2015 /etc/selinux/targeted/policy/policy.29
-r--r--r--. 1 root root 6.7M 9月  24 13:06 /etc/udev/hwdb.bin
-rw-r--r--. 1 root root 1.4M 3月   6 2015 /etc/brltty/zh-tw.ctb

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

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

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

  1. [root@bogon ~]# find /usr -not -user root -a -not -user bin -a -not -user hadoop

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

  3. /usr/share/polkit-1/rules.d

  4. /usr/libexec/abrt-action-install-debuginfo-to-abrt-cache

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

[root@bogon ~]# find /etc -not -perm -111 -ls

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

[root@bogon ~]# find /etc -mtime -7 -a -not \( -user root -o -user hadoop \)  -ls
101812290    0 drwx------   2 polkitd  root 63 9月 24 12:55 /etc/polkit-1/rules.d

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

(0)
answeranswer
上一篇 2016-09-26 08:57
下一篇 2016-09-26 09:35

相关推荐

  • Linux入门之常见文本处理工具

    Linux入门之常见文本处理工具 文本内容查看命令 cat   tac    rev  more  less   head   tail 普通文本查看 cat  tac  rev cat 命令 cat  [option]…

    Linux干货 2016-08-08
  • 文件的元数据

    2018-03-11

    2018-03-11
  • 正则表达式

         正则表达式是由一类特殊字符所编写的模式,通过这些字符的使用,我们能检索 查找文本中符合某些规则的内容。 正则表达式元字符的分类有:字符匹配,匹配次数,位置锚定,分组等。      字符匹配:      . : 匹配任意单个字符     &n…

    Linux干货 2017-04-06
  • 系统基础之shell脚本编程详解4(数组及字符串处理,变量赋值和配置文件)

    系统基础之shell脚本编程详解4(数组及字符串处理,变量赋值和配置文件)     今天来讲shell脚本编程的最后一些内容,数组及字符串处理,变量赋值和配置文件.这些内容也是我们经常在工作中使用到的知识点.下面让我们来详细了解下: 数组:   程序=指令+数据        &…

    Linux干货 2016-08-24
  • 磁盘管理之MBR与GPT分区

    磁盘管理之MBR与GPT分区 2016-08-26 zanghonglei%1 $ S 磁盘管理之MBR与GPT分区 linux下的文件分为常规文件和设备文件,常规文件一定在某一个设备上被存储,不论这个设备是真实的还是虚拟的,这里的设备是linux中vfs层中的设备,也就是设备文件中的设备,vfs层的设备分为字符设备和块设备,字符设备可以类比为一个…

    Linux干货 2016-08-29
  • 任务计划管理

    一:单一工作调度:at命令       列出在指定的时间和日期在计算机上运行的已计划命令或计划命令和程序。必须正在运行“计划”服务才能使用 at 命令。 示例: [root@CentOS 6 ~]#/etc/init.d/atd restart   启动服务 …

    Linux干货 2016-09-12

评论列表(1条)

  • luoweiro
    luoweiro 2016-10-12 00:07

    作业总结很赞,尤其是在find命令方面,当然还可以有更多详细的总结,有时间一定要补上,比如关于时间方面的find也是比较常用的。