N26-第五周

1、显示当前系统上rootfedorauser1用户的默认shell

[root@localhost test]# cat /etc/passwd | grep -E “^(root|fedora|user1)\>” |cut -d: -f  1,7

root:/bin/bash

user1:/bin/bash

fedora:/bin/bash

 

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

[root@localhost test]#  grep  -E  “\<[[:alpha:]]+\>\(\)” /etc/init.d/functions -o

 

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

[root@localhost test]# echo /tmp/test/ | grep -E “[^/]+/$”  -o

test/

扩展:取出其路径名

[root@localhost test]# echo /usr/bin | grep “^/.*”

/usr/bin

 

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

[root@localhost test]# ifconfig  | grep -E  “\<[0-9]|[0-9]{1}|[1][0-9]{2}|[2][0-5]{2}\>”  -o   

 

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

[root@localhost test]#  ifconfig | grep -o -E “(([0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])”

 

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

[root@localhost test]# grep -E -o “^[[:alnum:]]+[_]?[[:alnum:]]*@[[:alnum:]]+.[[:alpha:]]+” /tmp/test/1.txt

a@qq.com

asdf@qqq.com

124123@12.com

ff1321@fdsa.com

1_2@fsadf.cn

 

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

[root@localhost test]# find /var  -user root -a -group mail -ls

25165976    0 drwxrwxr-x   2 root     mail          104 226 16:24 /var/spool/mail

 

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

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

 

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

[root@localhost test]# find /  \(  -nouser -o -nogroup \) -a -atime -3

 

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

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

 

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

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

 

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

(0)
N26-xiaocongN26-xiaocong
上一篇 2017-02-26
下一篇 2017-02-26

相关推荐

  • 22期第七周课堂练习

    1、创建一个10G分区,并格式为ext4文件系统;        (1) 要求其block大小为2048, 预留空间百分比为2,   卷标为MYDATA, 默认挂载属性包含acl;        (2)   挂载至/data/mydata目录,要求挂载时禁止程…

    Linux干货 2016-10-09
  • 马哥教育网络班21期-第七周课程练习

    1、创建一个10G分区,并格式为ext4文件系统;    (1) 要求其block大小为2048, 预留空间百分比为2, 卷标为MYDATA, 默认挂载属性包含acl;    (2) 挂载至/data/mydata目录,要求挂载时禁止程序自动运行,且不更新文件的访问时间戳; [root@localhost ~…

    Linux干货 2016-08-29
  • 第三周 用户和组管理

    1、列出当前系统上所有已经登录的用户的用户名,注意:同一个用户登录多次,则只显示一次即可。 [root@localhost ~]# who root     pts/0        2017-12-16 22:46 (192.168.43.233) root     pts/1        2017-12-16 22:46 (192.168.43.233…

    2017-12-16
  • Python from entry to abandon 3

        第十章的内容是解决问题————编写一个Python脚本。在我的电脑上因为Zip命令不能正常工作所以无法给出演示。该章给出了很有意义的编程思路,对以后学习和工作都有不错的参考意义,这部分有兴趣的同学还是自己去看原版教程吧。    这篇博客结合个人笔记整理了《简明Python教程》第十一章到第十…

    Linux干货 2017-04-07
  • shell编程if及find查找作业

    写一个脚本/root/bin/createuser.sh,实现如下功能:使用一个用户名做为参数,如果指定参数的用户存在,就显示其存在,否则添加之;显示添加的用户的id号等信息 [root@www sh.log]# cat createuser.sh  #!/bin/bash #author #使用一个用户名作为参数,如…

    Linux干货 2016-08-16
  • Linux网络属性配置(三)修改配置文件&& CentOS 7 网络配置

    Linux网络属性配置(三)&& CentOS 7网络配置 Linux网络属性配置(三)修改配置文件&& CentOS 7 网络配置 Linux网络属性配置(三)修改配置文件 IP、MASK、GW、DNS相关配置文件: /etc/sysconfig/network-scripts/ifcfg-IFACE 路由相关配置文件: /…

    Linux干货 2016-07-07

评论列表(1条)

  • 马哥教育
    马哥教育 2017-03-06 19:21

    建议:像命令操作类的问题,可以附加一些结果,并于自己回看与他人的理解