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

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

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

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相同的用户的信息;

[root@localhost ~]# useradd bash
[root@localhost ~]# useradd testbash
[root@localhost ~]# useradd basher
[root@localhost ~]# useradd -s /sbin/nologin nologin
[root@localhost ~]# grep '^\([[:alnum:]]\+\).*\1$' /etc/passwd

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

[root@localhost ~]# grep -E '^(root|fedora|user1)\>' /etc/passwd | cut -d: -f1,7

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

法一:
[root@localhost ~]# grep "^[[:alpha:]]\+\(\)" /etc/rc.d/init.d/functions
法二:
[root@localhost ~]# grep -E  "^[[:alpha:]]+\(\)" /etc/rc.d/init.d/functions

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

[root@localhost ~]# echo "/mnt/abc" | grep -E -o "[^/]+/?$"
abc
[root@localhost ~]# echo "/mnt/abc/" | grep -E -o "[^/]+/?$"
abc/
[root@localhost ~]# echo "/mnt/abc/" | grep -E -o "[^/]+/?$" | cut -d"/" -f1
abc

   扩展:取出其路径名(?)

[root@localhost ~]# echo "/mnt/abc" | grep -E -o "^/[^/]+/" | cut -d"/" -f1,2
/mnt

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

[root@localhost ~]# ifconfig | grep -E -o "[1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]"

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

法一:
[root@localhost ~]# ifconfig | grep 'inet addr:' | cut -d: -f2 | cut -d' ' -f1
法二:
[root@localhost ~]# ifconfig | grep -oP '(?<=(inet addr:)).*?(?=\s+)'

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

法一:
[root@localhost /]# egrep "[a-zA-Z0-9_.-]+@[a-zA-Z0-9_.-]+\.[a-zA-Z0-9.]+" filename.txt
法二:
[root@localhost /]# grep -Eo '[0-9a-zA-Z_.-]+@[0-9a-zA-Z_.-]+' filename.txt
法三:
[root@localhost /]# grep -Eo "\b[A-Za-z0-9_.-]+@[A-Za-z0-9_.-]+\.[A-Za-z0-9]{2,6}\b" filename.txt

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

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

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

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

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

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

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

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

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

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

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 -a -not -user bin -a -not -user hadoop
法二:
[root@localhost ~]# find /usr -not \( -user root -o -user bin -o -user hadoop \)

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

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

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

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

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

(0)
上一篇 2016-07-12 11:15
下一篇 2016-07-12 11:15

相关推荐

  • 用户和权限管理

    一、用户 Linux中用户是资源获取的标识符,资源分配,文件系统安全权限模型的核心要素之一。密码则是用户认证的凭证,用户信息和密码信息都存放在相应的文本文件中,密码信息在存放的过程用了一定的加密算法进行加密。   1.加密算法: 资源分派:    Authentication:认证(确认身份,也有可能好几个人一个身份) &nbs…

    Linux干货 2016-08-05
  • 马哥教育21期网络班—第四周课程+练习

    1、复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其它用户均没有任何访问权限。 [root@localhost ~]#cp -rf /etc/skel /home/tuser1[root@localhost ~]#chmod -R g…

    Linux干货 2016-07-16
  • N26-第十三周

    1、建立samba共享,共享目录为/data,要求:(描述完整的过程)  1)共享名为shared,工作组为magedu;  2)添加组develop,添加用户gentoo,centos和ubuntu,其中gentoo和centos以develop为附加组,ubuntu不属于develop组;密码均为用户名;  3)添加samb…

    Linux干货 2017-06-01
  • mysql编译安装

    MYSQL编译安装:参考(http://v.youku.com/v_show/id_XMjc4MDUwNjYyOA==.html?from=s1.8-1-1.2&spm=a2h0k.8191407.0.0)(http://oldboy.blog.51cto.com/2561410/1917295)     编译安装mysql,最好…

    Linux干货 2017-06-09
  • HA之corosync+pacemaker+crmsh

    高可用集群框架 图片转载之http://www.178linux.com/16656 实验拓扑: 两台节点服务器: node1     192.168.150.137     node1.com node2     192.168.150.138     node2.com nf…

    Linux干货 2017-01-18
  • 二、(2)bash的工作特性之:命令执行状态返回值及命令行展开

    bash 工作特性 命令执行状态 命令行展开

    2018-01-10

评论列表(1条)

  • 马哥教育
    马哥教育 2016-07-12 14:29

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