马哥教育网络班21第五周练习作业

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

[root@localhost ~]# grep "^[[:space:]]\+" /boot/grub2/grub.cfg

 

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

[root@localhost ~]# grep "^#[[:space:]]\+[^[:space:]]" /etc/rc.d/rc.local

 

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

[root@localhost ~]# netstat -tan | grep 'LISTEN[[:space:]]\+$'

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

[root@localhost ~]# grep '^\([[:alpha:]]\+\):.*\1$' /etc/passwd

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

[root@localhost ~]# egrep '^(root|fedora|user1)\>' /etc/passwd | cut -d: -f7
/bin/bash
/bin/csh

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

[root@localhost ~]# grep '\<[[:alpha:]]\+\>()' /etc/rc.d/init.d/functions
checkpid() {
daemon() {
killproc() {
pidfileofproc() {
pidofproc() {
status() {
success() {
failure() {
passed() {
warning() {
action() {
strstr() {

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

基名:
[root@localhost ~]# echo "/tmp/log/txt" | egrep -o "[^/]+/?$"
txt
路径名:
[root@localhost ~]# echo "/tmp/log/txt" | egrep -o ".*/"
/tmp/log/

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

[root@localhost ~]# ifconfig | egrep -ow '\<[1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-5][0-5]\>'

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

egrep "(\<([0,1]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])\>\.){3}\<([0,1]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])\>"
注释:
[0,1]?[0-9]?[0-9]  :匹配0-199
2[0-4][0-9]  :匹配200-249
25[0-5]  :匹配250-255
([0,1]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])  :匹配0-255

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

[root@localhost ~]# egrep "^([[:alpha:]]|[0-9]|\_)*@([[:alpha:]]|[0-9])*.com$"

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

[root@localhost ~]# find /var -user root -group mail

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

[root@localhost ~]# find / -nouser -a -nogroup

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

[root@localhost ~]# find / -nouser -nogroup -mtime -3

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

[root@localhost ~]# find /etc -perm -222 -ls

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

[root@localhost ~]# find /etc -size +1M -type f -exec ls -lh {} \;

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 -o  -user bin -o  -user hadoop \) -ls

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

[root@localhost ~]# find /etc -not -perm -222 -ls

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

[root@localhost ~]# find /etc -mtime -7 -a -not -user root -a -not -user hadoop

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

(0)
N21-chenggbN21-chenggb
上一篇 2016-08-08 16:14
下一篇 2016-08-08 16:14

相关推荐

  • 第五周作业

    博客具体内容请移步博客园http://www.cnblogs.com/wangenzhi/p/6235456.html

    Linux干货 2016-12-30
  • 第五周博客作业

    1、显示当前系统上root、fedora或user1用户的默认shell; [root@localhost ~]# grep -E "^(root|fedora|user1)\>" /etc/passwd | cut -d: -f1,7 roo…

    Linux干货 2017-01-07
  • 如何将迁移home到独立分区中

        背景(centos7中):         由于在刚开始学习linux时磁盘分配追求简单,只是把一个磁盘简单的分了3个分区。现在,因用户数据增多、磁盘空间变少、当数据撑满磁盘时,会导致系统崩溃。为防止此种情况的发生我必须把把根下的/home 目录迁移出 来独立分…

    2017-08-10
  • python-多进程

    进程是由系统自己管理的。 1:最基本的写法 from multiprocessing import Pool def f(x):     return x*x if __name__ == '__main__': &nb…

    Linux干货 2016-11-05
  • 马哥教育网络班22期+第二周课程练习

    一、Linux上的文件管理类命令都有哪些,其常用的使用方法及其相关示例演示? cp命令:copy,有2类复制方法  1、单源复制:如果DEST不存在:则实现创建此文件,并复制源文件的数据流至DEST中;     如果DEST存在:如果DEST是非目录文件,则覆盖目标文件;如果DEST是目录文件,则先DEST目录下创建一个与源文件…

    Linux干货 2016-08-22
  • linux系统启动及kickstart

    1、简述linux操作系统启动流程
    2、简述grub启动引导程序配置及命令行接口详解
    3、实现kickstart文件制作与光盘镜像制作

    2018-01-17

评论列表(1条)

  • 马哥教育
    马哥教育 2016-08-17 15:36

    写的很好,排版也很棒,加油