马哥教育网络班21期+第五周课程练习

第五周作业

1、显示/boot/grub/grub.conf中以至少一个空白字符开头的行;
cat /boot/grub/grub.conf  | grep "^[[:space:]]\+"
2、显示/etc/rc.d/rc.sysinit文件中以#开头,后面跟至少一个空白字符,而后又有至少一个非空白字符的行;
cat /etc/rc.d/rc.sysinit | grep "^#[[:space:]]\+[[:alnum:]]"
3、打出netstat -tan命令执行结果中以‘LISTEN’,后或跟空白字符结尾的行;
netstat -tan | grep "LISTEN[[:space:]]*$"

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

useradd bashuseradd testbashuseradd basheruseradd nologin -s /sbin/nologingrep "^\([[:alnum:]]\+\>\).*\1$" /etc/passwd

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

egrep "^root\>|^fedora\>|^user1\>" /etc/passwd | awk -F: '{print $1":"$7}'

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

grep --color=auto "\<[[:alpha:]]\+()" /etc/rc.d/init.d/functions

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

echo "/home/www/dads" | grep -E -o "[^/]+/*$" | cut -d/ -f1

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

ifconfig | grep -o "\<[[:digit:]]\{1,\}\>"

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

ifconfig | grep -o -E "inet addr:[0-9.]+" | cut -d: -f2

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

echo "abcc@qq.com" | egrep "[[:alnum:]].*@[[:alnum:]].*(com|cn)"

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

find /var/ -user root -group mail -print

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

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

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

find /etc/ -type f -perm -a=w -print

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

find /etc/ -size +1M -type f -print

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

find /etc/init.d/ -type f -perm -a=x -a -perm -o=w -print

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

find /usr/ ! -user root -o ! -user bin -o ! -user hadoop -print

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

find /etc/ -perm u=-w -o -perm g=-w -o -perm o=-w

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

find /etc ! \( -user root -o -user hadoop \) -mtime -7 -print

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

(0)
N21_RodyN21_Rody
上一篇 2016-10-17 08:36
下一篇 2016-10-17 08:36

相关推荐

  • shell脚本编程和文件查找及压缩

    shell脚本编程 read:使用read来把输入值分配一个或多个shell变量     -p 指定要显示的提示     -t TIMEOUT     read 从标准输入中读取值,给每个单词分配一个变量   &nbsp…

    Linux干货 2016-08-18
  • man和history及bashi的快捷键

    man:帮助命令     命令格式:man# cmd;使用时可以先使用whatis 查询所对应的man的章节,然后用对应的man章节来查询帮助;     info:本地帮助文档     官方文档,在线查询等等,如果是付费版系统的话可以使用S…

    Linux干货 2016-07-29
  • 马哥教育网络班第21期+第五周课程作业

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

    Linux干货 2016-08-08
  • 用户管理

    http://www.jianshu.com/p/a07ae29ca345

    Linux干货 2017-07-23
  • N25第八周学习总结_sed命令详解

    sed使用详解 大纲: 1、    sed是什么 2、    为什么要使用sed 3、    sed使用方法 4、    sed详解   正题: 1、    sed是什么 sed全名Stream Ed…

    2017-02-26

评论列表(1条)

  • 马哥教育
    马哥教育 2016-10-25 13:52

    作业写的很好,但注意跟上进度