N25第五周作业

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

]# grep -E '^[[:space:]]+.*' /boot/grub/grub.conf

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

]# grep -E '^#[[:space:]]+[^[:space:]]+' /etc/rc.d/rc.sysinit

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

]# netstat -nat | grep -E '.*LISTEN[[:space:]]*'

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

]# grep -E '^(.*)\>.*\1$' /etc/passwd
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
bash:x:4007:4007::/home/bash:/bin/bash
nologin:x:4010:4015::/home/nologin:/sbin/nologin

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

]# grep -e ^root -e ^fedora -e ^user1 /etc/passwd | cut -d':' -f1,7
root:/bin/bash
user1:/bin/bash
fedora:/bin/bash

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

]# grep -E '\<[[:alpha:]]*\>\(\)' /etc/rc.d/init.d/functions

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

]# echo /etc/sysconfig/network-scripts/ifcfg-eth0 | grep -Eo '[^/]*/?$'
ifcfg-eth0

    扩展:取出其路径名

]# echo /etc/sysconfig/network-scripts/ifcfg-eth0 | grep -oP '/.*/(?=.?\b)'
/etc/sysconfig/network-scripts/

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

ifconfig | grep -E '\<([0-9]|([0-9][0-9])|(1[0-9][0-9])|(2[1-4][0-9])|(25[1-5]))\>'

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

]# ifconfig | grep -A 2 eth0 | grep -Eo '([0-9]{1,3}\.?){4}' | grep -v 255
172.20.51.128

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

]# grep -o '[[:alnum:]_.]*@[[:alnum:].]*'

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

]# find /var -user root -a -group mail
/var/spool/mail
/var/spool/mail/root

12、查找当前系统上没有属主或属组的文件;

]# find / -nouser -o -nogroup -type f
/var/spool/mail/mandriva
find: “/proc/10154/task/10154/fd/5”: 没有那个文件或目录
find: “/proc/10154/task/10154/fd/5”: 没有那个文件或目录
find: “/proc/10154/task/10154/fdinfo/5”: 没有那个文件或目录
find: “/proc/10154/task/10154/fdinfo/5”: 没有那个文件或目录
find: “/proc/10154/fd/5”: 没有那个文件或目录
find: “/proc/10154/fd/5”: 没有那个文件或目录
find: “/proc/10154/fdinfo/5”: 没有那个文件或目录
find: “/proc/10154/fdinfo/5”: 没有那个文件或目录
/home/mandriva
/home/mandriva/.bash_logout
/home/mandriva/.bash_profile
/home/mandriva/.bashrc
/home/mandriva/.gnome2

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

]# find / -type f -a -atime -3 -a \( -nouser -o -nogroup \)

13、查找/etc目录下所有用户都有写权限的文件;

]# find /etc -perm -222

14、查找/etc目录下大于1M,且类型为普通文件的所有文件;

]# find /etc -size +1M -a -type f | xargs ls -lh
-rw-r--r--. 1 root root 7.0M 11月 21 17:22 /etc/selinux/targeted/modules/active/policy.kern
-rw-r--r--. 1 root root 7.0M 11月 21 17:22 /etc/selinux/targeted/policy/policy.24

15、查找/etc/init.d/目录下,所有用户都有执行权限,且其它用户有写权限的文件;

[root@director ~]# touch /etc/init.d/test.txt
[root@director ~]# chmod 113 /etc/init.d/test.txt
[root@director ~]# find /etc/init.d/ -perm 
[root@director ~]# find /etc/init.d/ -perm -113 | xargs ls -lh
---x--x-wx 1 root root 0 12月 30 03:59 /etc/init.d/test.txt

16、查找/usr目录下不属于root、bin或hadoop的文件;

[root@director ~]# find /usr/ ! \( -user root -o -user bin -o -user hadoop \) -a -type f

17、查找/etc/目录下至少有一类用户没有写权限的文件;

]# find /etc/ ! -perm -222 -a -type f

18、查找/etc目录下最近一周内其内容被修改过,且不属于root或hadoop的文件;

]# find /etc/ -mtime -7 -a ! \( -user root -o -user hadoop \) -a -type f

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

(0)
N25_NvaN25_Nva
上一篇 2017-01-08 19:46
下一篇 2017-01-09 10:03

相关推荐

  • N25第三周视频博客 find命令详解

    视频作业:find命令详解 大纲:         1、什么是find 2、find能实现什么功能 3、为什么要使用find 4、如何使用find 5、find各参数详解   1、什么是find      find是linux 命令,它将档案系统内符合 expression(表达…

    Linux干货 2016-12-15
  • Linux Cluster之keepalived及keepalived + LVS DR的实现

      一、HA Cluster基础 系统可用性A=MTBF/(MTBF+MTTR) MTBF:平均无故障时间 MTTR:平均修复时间 降低MTTR的方式:冗余(redundent) 衡量标准:几个9 90%、99%、99.9%… 提升系统可用性的办法之一:降低MTTR 通过冗余(redundant)的方式能够避免单点故障(SPoF),从而…

    2016-11-02
  • 马哥linux 0726作业

    1,课堂练习 显示当前日期,格式:2016-08-08 显示前天是星期几 设置当前日期为2008-08-08 08:00 使用字符端登陆时,显示当前登录终端号,主机名和当前时间 1,首先我们知道当前登录信息的配置文件在/etc/issue中 2,然后我们查询帮助看看issue的具体描述查到了相关的mingetty的命令当中关于当中的一些选项就是我们需要的三个…

    Linux干货 2016-08-04
  • 基于samba服务的wordpress站点

    实验要求:             (1) samba server导出/data/app/web,在目录中提供wordpress;     (2) samba  client挂载nfs server导出的文件…

    2017-06-08
  • grep和正则表达式

    grep       作用:文本搜索工具,根据用户指定的“模式(过滤条件)”对目标文件逐行进行匹配检查;打印匹配到的行;       模式:由正则表达式的元字符及文本所编写出的过滤条件    语法:【选项】【文件】  &…

    2017-08-04
  • 进程及任务管理

    进程概念 内核的功用:进程管理、文件系统、网络功能、内存管理、驱动程序、安全功能等 Process: 运行中的程序的一个副本,是被载入内存的一个指令集合     进程ID(Process ID,PID)号码被用来标记各个进程     UID、GID、和SELi…

    Linux干货 2016-09-09

评论列表(1条)

  • 马哥教育
    马哥教育 2017-02-17 10:31

    写的很好,你的ip地址匹配是不是可以匹配到999.999.999.999?