马哥教育网络班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

相关推荐

  • linux终端变量设置,文件系统,man使用说明,文件类型

    一、定义终端提示符的变量 export PS1=’\e[32m[\e[33m\u\e[31m@\e[35m\h\e[36m\t\e[34m\#\e[31m\s\e[37m\W\e[32m]\$ ‘  `]# export 是个命令      PS1指终端提示符变量    &n…

    Linux干货 2013-06-16
  • 8月20日程序包管理

    程序包管理 概述    API:Application Program Interface应用编程接口    ABI:Application Binary Interface应用二进制接口    Unix-like,  …

    Linux干货 2016-08-21
  • KVM虚拟化平台部署及管理

    前言 KVM即Kernel Virtual Machine,最初是由以色列公司Qumranet开发。2007年2月被导入Linux 2.6.20核心中,成为内核源代码的一部分。2008年9月4日,Redhat收购了Qumranet,至此Redhat拥有了自己的虚拟化解决方案,之后便舍弃Xen开始全面扶持KVM,从RHEL6开始KVM便被默认内置于内核中。本文…

    Linux干货 2015-07-19
  • Linux的获取系统的帮助信息及man文档说明

    Linux的获取系统的帮助信息及man文档说明 帮助命令有内部命令帮助和外部命令帮助两种 内部命令获得帮助使用下面命令 # help COMMAND 例如: [root@localhost ~]# type type type is a shell builtin [root@localhost ~]# help type type: type [-afpt…

    2018-02-28
  • Find命令的使用

    Find命令的基本用法 在Linux系统中find命令是一个强大文件查找类工具,它支持根据文件名,权限,文件大小,访问以及修改时间查找,使用方法如下: find [option] [查找起始路径] [查找条件] [处理动作] 起始路径:指定查找文件或目录的路径,默认为当前目录 查找条件:可根据文件名,权限,文件大小以及从属关系查找文件 处理动作:动查找到的文…

    Linux干货 2017-08-28
  • N_28 linux基础知识

    1.计算机的组成
    2.linux的各发行版
    3.linux的哲学思想
    4.一些linux的基本命令
    5.帮助信息
    6.FHS

    2017-12-01

评论列表(1条)

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

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