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
下一篇 2017-01-09

相关推荐

  • DNS服务器以及子域授权

    1、安装bind      [root@www ~]# yum -y install bind 2、查看安装生成的文件      [root@www ~]# rpm -ql bind | less 3、程序路径     /var/named 4、配置…

    Linux干货 2017-05-31
  • 编译安装httpd-2.2.27.tat.gz及配置常见参数

    一、编译安装的整体步骤  1、在官网下载源码,并解压 2、切换到其目录中  3、执行./configure 4、编译   二、编译中及安装后配置常见的参数及其说明 编译中配置 1)指定安装路径 –prefix=/usr/local/Pacakage_name  指定安装路径 –sysc…

    Linux干货 2016-08-24
  • 第二周作业新

    一、Linux上的文件管理类命令都有哪些,其常用的使用方法及其相关示例演示。 pwd :显示当前所在路径   cd :切换目录   cd – :在上次目录与当前目录之间切换。   cd ~ :切换回自己的家目录   cd . :当前目录      cd .. :切换到…

    2017-02-18
  • RHCE系列之备份工具—-镜像备份Rsync

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://nolinux.blog.51cto.com/4824967/1431426     我一哥们最近在搞备份,需要用到rsync。因此,鄙人就简单总结了下rsync,也就有了这篇博文,希望对51…

    Linux干货 2016-08-15
  • bash编程初体验(三)

    bash编程初体验之for for while until 概述 本文将介绍以for为代表的循环语句在shell 脚本中的应用,常见的循环语句有for, while,until,作为循环语句,顾名思义,它就是重复地做一件事,直到满足某一条件而退出;另外,还有两个循环控制语句continue与break来配合循环语句,以实现临时中断或跳出循环的功能;以下为fo…

    Linux干货 2016-08-24
  • lamp的编译安装

    基于http的php模块模式 一、需要准备的软件:     apr-1.5.0.tar    apr-util-1.5.3.tar    httpd-2.4.9.tar        mysql-5.5.33-…

    Linux干货 2016-06-22

评论列表(1条)

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

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