N26 第五周作业

1、显示/boot/grub/grub.conf中以至少一个空白字符开头的行;

[root@localhost ~]# cat /boot/grub/grub.conf | grep "^[[:space:]]"

2、显示/etc/rc.d/rc.sysinit文件中以#开头,后面跟至少一个空白字符,而后又有至少一个非空白字符的行;

[root@localhost ~]# cat /etc/rc.d/init.d/functions | grep "^#[[:space:]]\+[^[:space:]]\+"

3、打出netstat -tan命令执行结果中以‘LISTEN’,后或跟空白字符结尾的行;

[root@localhost ~]# netstat -tan | grep "LISTEN[[:space:]]*$"

4、添加用户bash, testbash, basher, nologin (此一个用户的shell为/sbin/nologin),而后找出当前系统上其用户名和默认shell相同的用户的信息;

[root@localhost ~]# useradd bash
[root@localhost ~]# useradd testbash
[root@localhost ~]# useradd basher
[root@localhost ~]# useradd -s /sbin/nologin nologin
[root@localhost ~]# cat /etc/passwd | grep "^\([^:]\+\).*\1$"
[root@localhost ~]# cat /etc/passwd | grep -E "^([^:]+).*\1$"

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

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

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

[root@localhost ~]# cat /etc/rc.d/init.d/functions | grep -o "[_[:alpha:]]\+()"

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

[root@localhost ~]# echo "/var/log/yum.log" | grep -o "[^/]\+\/\?$" | grep -o "[^/]\+"
yum.log
[root@localhost ~]# echo "/var/log/yum.log" | grep -o ".*/"
/var/log/

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

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

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

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

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

[root@localhost ~]# echo "bac@sina.com.cn.org" | grep -E "^[_\.[:alnum:]]+@[^.]+(\.([[:alnum:]]+)){1,}"

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

[root@localhost ~]# find /var -user root -group mail -ls
201327980    4 drwxrwxr-x   2 root     mail         4096 Jan 26 11:41 /var/spool/mail
205901256  148 -rw-------   1 root     mail       150169 Jan 19 10:59 /var/spool/mail/root

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

[root@localhost ~]# find / -nouser -a -nogroup -ls
[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 hadoop -a -not -user bin -ls
[root@localhost ~]# find /usr -not \( -user root -o -user bin -o -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 -a -mtime -7 -ls

原创文章,作者:和风细雨,如若转载,请注明出处:http://www.178linux.com/67207

(0)
上一篇 2017-01-23 15:30
下一篇 2017-01-27 00:28

相关推荐

评论列表(1条)

  • 马哥教育
    马哥教育 2017-03-02 20:05

    百尺杆头,再进一步。