第五周作业

1、显示/boot/grub/grub.conf中以至少一个空白字符开头的行;
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 scripts]# tail -4 /etc/passwd
bash:x:3010:3010::/home/bash:/bin/bash
testbash:x:3011:3011::/home/testbash:/bin/bash
basher:x:3012:3012::/home/basher:/bin/bash
nologin:x:3013:3013::/home/nologin:/sbin/nologin

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

5、显示当前系统上root、fedora或user1用户的默认shell;
[root@localhost ~]# grep -E “^(root|fedora|user1)\>” /etc/passwd | cut -d: -f7

6、找出/etc/rc.d/init.d/functions文件中某单词后面跟一组小括号的行,形如:hello();
[root@localhost ~]# grep -E “[[:alnum:]]+()” /etc/rc.d/init.d/functions
7、使用echo命令输出一个绝对路径,使用grep取出其基名;
[root@localhost ~]# echo /etc/rc.d/init.d/functions | grep  -o  “[^/]+/\?$”
扩展:取出其路径名
[root@localhost ~]# echo /etc/rc.d/init.d/functions | grep -E  -o “^/./”

8、找出ifconfig命令结果中的1-255之间数字;
[root@localhost ~]# ifconfig | grep  -E  -o  
“\<([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\>”

9、挑战题:写一个模式,能匹配合理的IP地址;
[root@localhost ~]# ifconfig | grep  -E  -o  
“([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])”

[root@localhost~]# ifconfig | grep -E 
“(2[0-4][0-9]|25[0-5]|[01]?[0-9][0-9]?.){3}(2[0-4][0-9]|25[0-5]|[01]?[0-9][0-9]?)”

10、挑战题:写一个模式,能匹配出所有的邮件地址;
[root@localhost ~]# grep -E “[0-Z]{3,}\@[0-Z]{2,}(.[0-Z]{2,})+” /tmp/mail.txt

11、查找/var目录下属主为root,且属组为mail的所有文件或目录;
[root@localhost ~]# find /var/  -user root -a -group mail -ls

12、查找当前系统上没有属主或属组的文件;
[root@localhost ~]# find /var/  -user root -a -group mail -ls
     进一步:查找当前系统上没有属主或属组,且最近3天内曾被访问过的文件或目录;
[root@localhost ~]# find /
-nouser -a -nogroup -a -atime -3 -ls

13、查找/etc目录下所有用户都有写权限的文件;
[root@localhost ~]# find /etc -perm -222 -ls

14、查找/etc目录下大于1M,且类型为普通文件的所有文件;
[root@localhost ~]# find /etc -size +1M -type f -ls

15、查找/etc/init.d/目录下,所有用户都有执行权限,且其它用户有写权限的文件;
[root@localhost ~]# find /etc/init.d/ -perm -113  -ls

16、查找/usr目录下不属于root、bin或hadoop的文件;
[root@localhost ~]# find /usr -not -user root -a -not -user bin -a -not -user hadoop -ls

17、查找/etc/目录下至少有一类用户没有写权限的文件;
[root@localhost ~]# find /etc/ -not -perm -222  -ls

18、查找/etc目录下最近一周内其内容被修改过,且不属于root或hadoop的文件;
[root@localhost ~]# find /etc/  -not -user root -a -not -user hadoop -mtime -7 -ls
[root@localhost ~]# find /etc -not ( -user root -o -user hadoop ) -mtime -7 -ls

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

(0)
anhui-binbinanhui-binbin
上一篇 2017-03-09 17:24
下一篇 2017-03-10 13:21

相关推荐

  • MariaDB数据类型总结

        数据类型是数据的一种属性,它决定了数据的存储格式、有效范围及其它相应的限制。MariaDB的数据类型包括:字符型、整型、浮点值、日期时间型、布尔型及内建类型。 一、字符型     1、CHAR和VARCHAR类型     &nbsp…

    Linux干货 2015-06-30
  • 小练习题。【第五周】

    1、显示当前系统上root、fedora或user1用户的默认shell; /]# cat /etc/passwd | grep '^root\|fedora\|user1' |cut -d':' -f1,7 2、找出/etc/rc.d/i…

    Linux干货 2016-11-26
  • 苦上半年时间

    这是一种享受

    Linux干货 2016-08-08
  • 马哥教育网络21期+第十一周练习博客(上)

    马哥教育网络21期+第十一周练习博客(上) 1、详细描述一次加密通讯的过程,结合图示最佳。 加密同性过程中使用到最重要的就是openssl     安全加密传输过程中要确保如下几个环节:     保密性:数据保密性,隐私性     完整性:…

    Linux干货 2016-09-26
  • Linux LVM

    Linux LVM 前言     LVM是 Logical Volume Manager(逻辑卷管理)的简写,它是Linux环境下对磁盘分区进行管理的一种机制,它由Heinz Mauelshagen在Linux 2.4内核上实现,目前最新版本为:稳定版1.0.5,开发版 1.1.0-rc2,以及LVM2开发版。无论在Linux或者其他类似…

    系统运维 2016-04-24

评论列表(1条)

  • 马哥教育
    马哥教育 2017-03-14 09:05

    第9题还可以有更简单的方法~可以再挑战下自己~~继续加油!