第五周作业

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

[root@unclez ~]#  grep -E "^[[:space:]]+.*" /boot/grub/grub.cong

2、显示/etc/rc.d/rc.sysinit文件中以#开头,后面跟至少一个空白字符,而后又有至少一个非空白字符的行;

[root@unclez boot]#  grep -E "^#[[:space:]]+[^[:space:]]+" /etc/rc.d/rc.sysinit

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

[root@unclez ~]# netstat -tan | grep -i "listen[[:space:]]*$"

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

[root@unclez ~]# useradd bash
[root@unclez ~]# useradd testbash
[root@unclez ~]# useradd basher
[root@unclez ~]# useradd -s /sbin/nologin nologin
[root@unclez ~]# cat /etc/passwd | tail -4
bash:x:1002:1002::/home/bash:/bin/bash
testbash:x:1003:1003::/home/testbash:/bin/bash
basher:x:1004:1004::/home/basher:/bin/bash
nologin:x:1005:1005::/home/nologin:/sbin/nologin

[root@unclez ~]# grep -E "^([^:]+\>).*\1$" /etc/passwd
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
bash:x:1002:1002::/home/bash:/bin/bash
nologin:x:1005:1005::/home/nologin:/sbin/nologin

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

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

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

[root@unclez ~]# grep -E -o "[[:alnum:]]+\(\)" /etc/rc.d/init.d/functions

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

[root@unclez ~]# echo /etc/sysconfig/network-scripts | grep -E -o '[^/]+/?$'

扩展:取出其路径名

[root@unclez ~]# echo /etc/sysconfig/network-scripts | grep -E -o '^/([^/]+/)+'

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

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

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

grep -E -o "\<[A-Za-z0-9_]+@[A-Za-z0-9.]+\.[A-Za-z]\>" mail

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

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

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

[root@unclez ~]# find / -nouser -nogroup -type f

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

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

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

[root@unclez ~]# find /etc -perm 222 -type f -ls

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

[root@unclez ~]# find /etc -size +1M -type f | xargs ls -lh

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

[root@unclez ~]# find /etc/init.d -perm 113 -type f -ls

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

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

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

[root@unclez ~]# find /etc/ -not -perm /222 -type f -ls

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

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

原创文章,作者:N25-赵叔,如若转载,请注明出处:http://www.178linux.com/65471

(0)
N25-赵叔N25-赵叔
上一篇 2016-12-31 21:36
下一篇 2016-12-31 23:32

相关推荐

  • rpm包管理

    一、概述 RPM 是RPM Package Manager(RPM软件包管理器)的缩写。由redhat公司的Redhat package manager改名而来,成了RedHat的工业标准 二、rpm的命名格式: rpm包的命名格式:name-version-relase.arch.rpm version: major.minor.release,同源代码 …

    Linux干货 2015-10-07
  • centos7上实现LAMP,并搭建wordpress

    实验:LAMP的架构,并搭建wordpress              1、准备环境,                      #mkdir src    …

    2017-08-07
  • 文本处理工具之AWK

    概述:     在之前的文章中,我们介绍过文本处理三剑客的grep、sed,本篇就简要说明下awk的用法。主要是围绕常见的一些用法进行展开,分为以下几个部分:     1、awk的基础语法     2、awk的进阶语法  &nbs…

    Linux干货 2016-09-20
  • ftp的用户权限配置

    文件服务: 应用层:ftp; 内核级网络文件系统:nfs POSIX(可移植操作系统接口 Portable Operating System Interface of UNIX,缩写为 POSIX ) API(应用程序编程接口) 跨平台的网络文件系统:cifs (samba)   网络存储: NAS:NetworkAttached Stoage,文…

    Linux干货 2017-05-02
  • 系统基础之sed工具详解

    sed工具详解 NAME:  sed – stream editor for filtering and transforming text(实现文本替换和过滤功能)  类型: 行编辑器(流) 特点: 把文件中的每一行加载到内存中,匹配模式,把能够匹配到模式的内容输出到屏幕,不修改原文件 工作模式:   每一次读取一…

    Linux干货 2016-08-10
  • 生产环境网卡绑定汇总(bonding,team)

    生产环境网卡绑定汇总 1 什么是bonding,team?   1.1 bonding,team简介    在了解正式的概念之前,我们先从不太专业的角度取解释这两个名词。    所谓bonding就是联结。以下是来自柯林斯英汉双解大词典对于bonding的解释。    the proces…

    Linux干货 2017-05-07

评论列表(1条)

  • 马哥教育
    马哥教育 2017-02-17 10:57

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