马哥教育网络班20期+第5周课程练习

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.sysinit

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

[root@localhost ~]# netstat -tan |grep "LISTEN[[:space:]]\?"

     

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

useradd bash

useradd testbash

useradd basher

useradd -s /sbin/nologin nologin

 

[root@localhost ~]# grep -E '^(\<[a-z]+\>).*\1$' /etc/passwd

 

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

     grep -E "^(root|fedora|user1)\>" /etc/passwd |cut -d: -f7 

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

[root@localhost ~]#  grep "\<.*\>()" /etc/rc.d/init.d//functions

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

[root@localhost ~]# echo /etc/sysconfig/network-scripts/ifcfg-eth0 | grep -Eo "(\<[^/]+?)$"

ifcfg-eth0

   

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

[root@localhost ~]# ifconfig | egrep "\<([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\>"

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

[root@localhost ~]# ifconfig | egrep -o "[1-9]{1,3}\.[1-9]{1,3}\.[1-9]{1,3}\.[1-9]{1,3}" 

192.168.117.128

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

[root@localhost ~]# cat mail.txt  | grep '[[:alnum:]]\+@[[:alnum:]]\+\.[[:alnum:]]\+$'

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

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

/var/spool/mail

/var/spool/mail/root

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

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

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

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

     

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

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

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

[root@localhost ~]# find  /etc -type f -size +1M

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

[root@localhost ~]#  find /etc/init.d/ ! -perm 112 |ls -lrt

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

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

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

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

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

[root@localhost ~]#  find /etc/ -type f -ctime -7  -a ! \( -user root -o -user hadoop \) -ls

找出/etc/passwd文件中一位数或两位数;

    # grep '\<[0-9]\{1,2\}\>'   /etc/passwd  #其中一对尖括是用来锚定的,

                    要不然像1234,这样的数也会匹配到的,题目中明确1位或2位

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

(0)
Net20_KenNet20_Ken
上一篇 2016-08-15 09:26
下一篇 2016-08-15 10:52

相关推荐

  • dd工具

    dd     dd命令:convert and copy a file     用法:        ddif=/PATH/FROM/SRC of=/PATH/TO/DEST       &…

    Linux干货 2016-09-02
  • Linux基础之用户及组管理

    grep扩展应用,用户管理,组管理,用户及组管理命令

    2018-01-31
  • class13 shell编程(五)软件包管理(三)

    一、shell编程(五) 位置变量补充 shift (踢掉参数) shift                #! /bin/bashecho "1st arg …

    Linux干货 2016-08-24
  • grep文本查找和正则表达式

    一、grep grep: (Global search REgular expression and Print outthe line)全局查找正则表达式并且打印结果行。不会对输入的文本进行修改。 Unix的grep家族包括grep、egrep和fgrep,egrep是grep的扩展,支持更多的正则元字符; fgrep就是fixed grep或f…

    Linux干货 2016-08-07
  • N25第四周总结

    linux bassic Week 4 Blogging 1、复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其它用户均没有任何访问权限。 ~]# cp -r /etc/skel/   /home/tuser1/ ~]# chmod&n…

    Linux干货 2016-12-26
  • 常用文本处理命令练习

    1、列出当前系统上所有已经登录的的用户的用户名,注意同一用户登录多次,则只显示一次 [root@keyou ~]#  w -hs | cut -d' ' -f 1 | sort -u  gentoo …

    系统运维 2016-11-13

评论列表(1条)

  • 马哥教育
    马哥教育 2016-08-17 14:29

    写的很好,排版还可以在漂亮一点,加油,ip地址的扩展不对