从Linux小白到大牛——与狼共舞的日子5

马哥教育网络班21期+第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 ~]# egrep '^(root|fedora|user1)\>' /etc/passwd | cut -d: -f1,7

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


[root@localhost ~]# egrep -o '^[_[:alpha:]]+\(\)' /etc/rc.d/init.d/functions

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


[root@localhost ~]# echo '/a/b/c' | egrep -o '[^/]+/?$' | cut -d'/' -f1


[root@localhost ~]# echo /a/b/c/ | egrep  -o   '^/\<.*/\<'

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


[root@localhost ~]# ifconfig | egrep -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 | egrep -o "(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])"

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


[root@localhost ~]# echo aa@126.com |  grep '[[:alnum:]]\+@[[:alnum:]]\+\.[[:alnum:]]\+$'

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


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

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


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


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

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


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

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


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

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


[root@localhost ~]# find /etc/init.d -perm -113

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


[root@localhost ~]# find /usr -not -user root -a -not -user bin -a -not -user hadoop

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


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

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


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

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

(0)
N21_孤狼N21_孤狼
上一篇 2016-08-31
下一篇 2016-08-31

相关推荐

  • 走进Linux(二)

    Linux基础知识 1、文件管理类命令 mkdir:创建空目录 格式 mkdir [选项](可跟多个选项) 要创建的目录名 选项 -p:递归创建多个目录                             &nbsp…

    Linux干货 2016-09-26
  • Linux grep与正则表达式浅析

    #Linux grep与正则表达式浅析 ##grep   grep(global search regular expression(RE) and print out the line,全面搜索正则表达式并把行打印出来)是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹配的行打印出来。 ###grep语法    &n…

    Linux干货 2017-04-06
  • 学习标准I/O和管道的心得体会

    重定向、标准输出、标准输入、标准错误、管道的命令整理

    2017-11-20
  • 第五周作业

    1、简述rpm与yum命令的常见选项,并举例 rpm 命令 linux的的包管理器,用于对rpm软件包,进行安装、升级、卸载、查询、校验等操作。 使用语法: rpm [OPTIONS] [PACKAGE_FILE] 常用选项: 安装: -i,–install 升级: -U,–update,-F,–freshen 卸载: -…

    Linux干货 2017-12-14
  • 马哥教育网络班20期+第5周课程练习

    1、显示/boot/grub/grub.conf中以至少一个空白字符开头的行; grep "^[[:space:]]\+.*" /boot/grub/grub.conf   2、显示/etc/rc.d/rc.sysinit文件中以#开头,后面跟至少一个空白字符,而后又有至少一个非空白字符的行; grep&nb…

    Linux干货 2016-07-12
  • Zet Casino: Ihr führendes zet online casino in Deutschland!

    Zet Casino: Ihr führendes zet online casino in Deutschland! Hier kann ich dir besonders das faszinierende Lightning Roulette ans Herz legen. Aber auch viele weitere Versionen für B…

    Linux干货 2025-05-14

评论列表(1条)

  • 马哥教育
    马哥教育 2016-09-07 17:42

    非常的漂亮,如果能解释一下各命令的参数意义就更好了,加油。