第五周作业

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

相关推荐

  • 计算1000以内的总质数个数

    #include <stdio.h> int main() { int micro[500]; // 质数保存素组 int number = 0; // 质数个数 micro[number++] = 2; // micro[0]=2 micro[number++] = 3; // micro[1]=3, number=2 unsigned lon…

    Linux干货 2017-03-22
  • linux文件权限

                                                      &nbsp…

    Linux干货 2016-08-04
  • Linux内核介绍

                               Linux内核介绍 严格来讲,Linux这个词本身只表示Linux内核,但实际上人们已经习惯了用Linux来形容整个基于Linux内核,并且使用GNU工程各种工具和数…

    Linux干货 2016-10-27
  • vim练习题

    #复制/etc/profile至/tmp/目录,用查找替换命令删除/tmp/profile文件中的行首的空白字符vim /tmp/profile%s@^[[:space:]]+@@g#复制/etc/rc.d/init.d/functions文件至/tmp目录,用查找替换命令为/tmp/functions的每行开头为空白字符的行的行首添加一个#号vim…

    Linux干货 2017-06-03
  • vim编辑器-练习题

    1 、复制/etc/profile至/tmp/目录,用查找替换命令删除/tmp/profile文件中的行首的空白字符 #cp /etc/profile /tmp #vim /tmp/profile :%s/^[[:space:]]\+// 2 、复制/etc/rc.d/init.d/functions 文件至/tmp 目录,用查找替换命令为/tmp/func…

    Linux干货 2016-08-15

评论列表(1条)

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

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