N25-第5周博客作业

N25-第5周博客作业

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

grep -E "^[[:space:]]+[[:alnum:]]+" /boot/grub/grub.conf   
grep "^[[:space:]]\+.*" /boot/grub/grub.conf

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

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

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

netstat -tan | grep -E "LISTEN[[:space:]]*$"
netstat -tan | grep "LISTEN[[:space:]]*$"

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

添加用户什么的略。。。 

grep "^\([a-z]\+\b\).*\1$" /etc/passwd

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

grep -E "^(root|fedora|user1)\>" /etc/passwd | cut -d: -f1,7
grep -E "^(root|fedora|user1)\b.*" /etc/passwd | cut -d: -f1,7

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

grep -E "[[:alpha:]]+\>\(\)" /etc/rc.d/init.d/functions 
grep "[[:alnum:]]\+()" /etc/rc.d/init.d/functions

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

    扩展:取出其路径名

echo "/usr/local/nginx/sbin/" | grep -E -o "[[:alnum:]]+/?$" | grep -o "[[:alnum:]]*" 
echo "/usr/local/nginx/sbin/" | grep -E -o "[/[:alnum:]]+\>" | grep -E -o "^/[/[:alnum:]]+/"

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

ifconfig | grep -E -o "\<[1-9]\>|\<[1-9][0-9]\>|\<1[0-9][0-9]\>|\<2[0-4][0-9]\>|\<25[0-5]\>"
ifconfig | grep  -E -o "\b(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]{1,2})\b"

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

ifconfig | grep -E -o "\<((1?[0-9][0-9]?|2[0-4][0-9]|25[0-4])\.){3}(1?[0-9][0-9]?|2[0-4][0-9]|25[0-4])\>"

 

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

grep -E -o "\<[^[:space:]]*\>@\<[^[:space:]]*\>\.\<[^[:space:]]*\>" mailstest.text 
grep -E -o "\b[^[:space:]]+\@[^[:space:]]+\b" mailstest.text

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

find /var -user root -group mail -ls

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

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

find / \( -nouser -o -nogroup \) 
find / \( -nouser -o -nogroup \) -a -atime -3

 

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

find /etc  -perm -222 -ls

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

find /etc -size +1M -type f -exec ls -lh {} \;

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

find /etc/init.d/ -perm -113
find /etc/init.d/ -perm -113 -exec ls -lh {} \;

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

find /usr/ -not \( -user root -o -user bin -o  -user hadoop \)

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

find /etc/ -not -perm  -222

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

find /etc -mtime -7 -not \( -user root -o -user hadoop \) -ls

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

(0)
oranixoranix
上一篇 2016-12-30
下一篇 2016-12-31

相关推荐

  • 学习宣言

    失败是留给不坚持的人·······

    Linux干货 2016-12-27
  • 马哥教育络班22期-第1周博客作业

    第一周博客作业 1 描述计算机的组成及其功能 计算机由硬件和软件两大部分组成: 1.1 计算机硬件组成与功能 计算机硬件由运算器、控制器、存储器、输入设备、输出设备五大部分组成。 1.1.1 运算器 算术逻辑部件ALU,执行算术运算和逻辑运算。例如:加减乘除,移位,取模。运算器的核心是加法器。 1.1.2 控制器 控制器是计算机的指挥中心,它的主要作用是按照…

    Linux干货 2016-08-14
  • 文本处理工具sed、vim

    文本处理工具sed、vim 一、sed的使用 1、sed的概念 sed简单地说sed是一种行处理工具。 sed 是一种流性的行编辑器,它一次处理一行内容。处理时,把当前处理的行存储在临时缓冲区中,称为“模式空间”(pattern space ),接着用sed 命令处理缓冲区中的内容,处理完成后,把缓冲区的内容送往屏幕。接着处理下一行,这样不断重复,直到文件末…

    Linux干货 2016-08-11
  • Mysql 备份

    Mysql 备份 ============================================================================= =============================================================================    &n…

    2016-11-22
  • 利用heartbeat v2版搭建高可用mysql

    一、实验环境  1)实验图        2)同步时间;确保可以使用主机名通信;确保可以使用ssh秘钥方式进行彼此登录;由于是两台设备,需要仲裁;  确保可以使用主机名通信 web1修改hosts文件如下: 172.16.2.12 SQL1.linux.com SQL1 172.…

    Linux干货 2015-07-08
  • 用户和组相关的配置文件

    目录 l  用户 l  组账号 l  UID和GID号 l  /etc/passwd分析 l  /etc/shadow分析 l  /etc/group分析 l  /etc/gshadow分析 l  通过用户和用户组配置文件来查询或管理用户 l  总结 1、用户(User…

    Linux干货 2016-10-23

评论列表(1条)

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

    写的很好,排版也很漂亮,继续加油