N22-第五周作业-冥界之王

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

   [root@CentOS6 ~]# cat /boot/grub/grub.conf | grep -E  "^[[:space:]]{1,}"

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

   [root@CentOS6 ~]# cat /etc/rc.d/rc.sysinit | grep -E "^#[[:space:]]{1,}[^[:space:]]"

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

   [root@CentOS6 ~]# netstat -tan | grep "LISTEN[[:space:]]"

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

   [root@CentOS6 ~]# useradd bash
   [root@CentOS6 ~]# useradd testbash
   [root@CentOS6 ~]# useradd basher
   [root@CentOS6 ~]# useradd nologin -s /sbin/lologin

    2种方法找出当前系统上其用户名和默认shell相同的用户的信息

   [root@CentOS6 ~]# cat /etc/passwd | grep `echo $SHELL` | awk -F ":" '{printf "%s\n", $1}'
   [root@CentOS6 ~]# cat /etc/passwd | grep `echo $SHELL` | cut -d ":" -f1

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

   [root@CentOS6 ~]# cat /etc/passwd | grep -E "^\<root|^\<fedora|^\<user1" | cut -d ":" -f1,7
   [root@CentOS6 ~]# cat /etc/passwd | grep -E "^\<root|^\<fedora|^\<user1" | awk  -F ":" '{printf "%s:%s\n",$1,$7}'

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

   [root@CentOS6 ~]# cat /etc/rc.d/init.d/functions | grep  "\<[[:alnum:]].*\>()"

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

   取出目录:  

   [root@CentOS6 yum.repos.d]# echo "/etc/yum.repos.d/CentOS-install.repo" | grep -E "^/.*/" --color -o

    取出文件名:

   [root@CentOS6 etc]# echo "/etc/yum.repos.d/CentOS-install.repo" | grep -E "[^/]+/?$" --color -o

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

   [root@CentOS6 yum.repos.d]# ifconfig | grep -E "[1-9]|[1-9][0-9]|1[0-9]{1,2}|2[0-4][0-9]|25[0-5]" --color

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

   [root@CentOS6 ~]# ifconfig | grep -E "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)" --color -o

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

   [root@CentOS6 ~]# echo "lihui@hotmai.com" | grep -E "^([a-zA-Z0-9_\-\.\+]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$" --color -o

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

   [root@CentOS6 ~]# ls -l /var | grep "root mail"
   [root@CentOS6 var]# find /var -user root -a -group mail -ls

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

   [root@CentOS6 etc]# find / -nouser -o -nogroup -ls
   [root@CentOS6 etc]# find / \( -nouser -o -nogroup \) -atime -3

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

   [root@CentOS6 var]# find /etc/ -perm -222 -ls

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

   [root@CentOS6 etc]# ls -lh `find /etc/ -size +1M -a -type f`

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

   [root@CentOS6 etc]# find /etc/init.d -perm 113 -o -type

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

   [root@CentOS6 etc]# find /usr -not \( -user root -o -user bin -o -user hadoop \) -type f -ls

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

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

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

  [root@CentOS6 etc]# find /etc -mtime -7 -not \( -user root -o -user hadoop \) -type f -ls

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

赞 (0)
lihuisjsqlihuisjsq
上一篇 2016-09-19 13:49
下一篇 2016-09-19 13:49

相关推荐

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

    Mairadb 编译安装Mairadb数据 先下载mariadb的软件包: 将软件包解压缩到/usr/local目录下 ]# tar xf mariadb-5.5.32-linux-x86_64.tar.gz -C /usr/local/ 创建连接 ]# ln -sv maria…

    Linux干货 2016-10-17
  • 【N25第七周作业】

    1、创建一个10G分区,并格式为ext4文件系统;    (1) 要求其block大小为2048, 预留空间百分比为2, 卷标为MYDATA, 默认挂载属性包含acl; [root@localhost ~]# mke2fs -t ext4 -b 2048 -m 2 -L MYDATA /dev/sdb1 mke2fs 1.42.9 (28…

    2017-04-13
  • 第五周:grep和find的使用练习

    1、显示当前系统上root、fedora或user1用户的默认shell; grep -E "^(root|fedora|user1)" /etc/passwd | cut -d: -f7 grep -E "^root|fedora|use…

    Linux干货 2016-10-25
  • SHELL网络爬虫实例剖析

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://nolinux.blog.51cto.com/4824967/1552472        前天简单分享了用 shell 写网络爬虫的一些见解,今天特地把代码发出来与51博…

    Linux干货 2016-08-15
  • bash脚本编程之select语法详解

    shell编程之select select控制结构(在tcsh中不可用)基于Korn Shell中的控制结构 select语句首先显示一个菜单,然后根据用户的选择给变量赋予相应的值,最后执行一系列命令 其语法如下: select varname in list do commands done select 表达式是一种bash的扩展应用,动作包括: 自动用…

    Linux干货 2016-08-24