第五周作业

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

相关推荐

  • 初学Linux之用户、组和权限

    1、用户和组管理命令 
    2、理解文件权限和默认权限 
    3、设置文件权限
    4、特殊权限 
    5、ACL

    2017-12-08
  • 20 shell脚本编程1

    20 shell脚本编程1 一、杂项知识整理 1、脚本文件格式:     #!/bin/bash     (注释信息:)     #description:say hello     #vesion:…

    Linux干货 2016-08-11
  • Linux常用命令

    一、Linux常用命令(总) 二、Linux常用命令(分) 1、pwd – print name of current/working directory 2、cd – change directory 3、ls – list,dieplay directory content 4、date – pr…

    Linux干货 2016-09-19
  • 如何修复系统问题–实验

    实验一: MBR的数据被破坏了,系统无法开机启动,如果有光盘,会自动启动光盘,因为在检查的时候,认为是没有硬盘设备的 dd if=/dev/zero of=/dev/sda bs=1 count=446 1. 进入光盘的救援模式中2. 切根  chroot /mnt/sysimage/   再使用 grub-install /d…

    Linux干货 2017-09-03
  • 8-15作业

    1、写个脚本,实现以下三角形    *   ***  ***** ******* #!/bin/bash # read -p " input a number : " n for l&nbs…

    Linux干货 2016-08-21
  • Mozart的剑(文本处理工具)——壹剑(文本查看cat、more、less)

    壹剑(文本查看cat、more、less) 博客之前突然想起两句话,很有意思的话,在此贴出上句,希望可以与大家分享,不可问度娘,有兴趣的可以试试。 上句:烟锁池塘柳    下句: 上句:因荷而得藕    下句: 1>cat命令是Linux系统下的一个文本输出命令,一般是用于观看某个文件的内容,特点:一次性显示整个…

    2017-07-29

评论列表(1条)

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

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