第五周作业

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)
上一篇 2017-03-09 17:24
下一篇 2017-03-10 13:21

相关推荐

  • 马哥教育网络班21期-第七周课程练习

    第七周作业 1、创建一个10G分区,并格式为ext4文件系统; [root@qq ~]# fdisk /dev/sdb         #使用fdisk命令进行分区; Device contains neither&nb…

    Linux干货 2016-08-08
  • raid5创建

    创建分区并改类型 创建raid5   创建把文件系统 生成配置文件    

    2017-12-17
  • GRUB加密、修复和破解密码实战指南

    GRUB加密、修复和破解密码实战指南 GRUB(Boot Loader) 从系统启动流程可以得知,在BIOS读取相关信息之后,接下来是去第一个可以启动的设备当中的MBR中读取Boot Loader信息,Boot Loader提供具有菜单功能、直接加载内核信息,以及相关的控制权转交功能。所以说系统启动必须要有Boot Loader,然后才能去加载内核。 Boo…

    Linux干货 2016-09-19
  • awk详解

    —————————— 课外练习 只处理用户ID为奇数的行,并打印用户名和ID号 [root@localhost ~]# awk -F: '{if($3%2!=0) {print&n…

    Linux干货 2016-09-25
  • M20-1 8月3号作业

    1、三种权限rwx对文件和目录的不同意义 2、umask和acl mask 的区别和联系 3、三种特殊权限的应用场景和作用 4、设置user1,使之新建文件权限为rw——- 5、设置/testdir/f1的权限,使user1用户不可以读写执行,g1组可以读写 /testdir/dir的权限,使新建文件自动具有acl权限:user1:r…

    Linux干货 2016-08-05
  • raid各级别简介

    一. raid 是什么       RAID:(Redundant Array of indenpensive Disk) 独立磁盘冗余阵列: 磁盘阵列是把多个磁盘组成一个阵列,当作单一磁盘使用,它将数据以分段(striping)的方式储存在不同的磁盘中,存取数据时,阵列中的相关磁盘一起动作,大幅减低数据的存…

    Linux干货 2016-02-14

评论列表(1条)

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

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