第五周作业

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

grep
“^[[:space:]]\+” 
/boot/grub/grub.conf

grep  -E 
“^[[:space:]]+” 
/boot/grub/grub.conf

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

grep
“^#[[:space:]]\+[^[:space:]]\+” /etc/rc.d/rc.sysinit

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

netstat -tan | grep
“LISTEN[[:space:]]*$”

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

 useradd bash

useradd testbash

useradd basher

useradd nologin

usermod -s
/sbin/nologin nologin

grep  –color=auto 
“\/sbin\/nologin$” /etc/passwd

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

grep -E “^root|^fedora|^user1” /etc/passwd –color=auto | cut -d: -f1,7

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

 grep -E “\<[[:alpha:]]+\>\(\)”
/etc/rc.d/init.d/functions  –color=auto

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

    扩展:取出其路径名

echo
“/hyp/test/ly/e” | grep -o “\<[[:alpha:]]\+\>\/\?$”
–color=auto

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

grep -Eo ”

((2[0-4][0-9])|(25[0-5])|([0-1]?[0-9]?[1-9]))

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

grep -Eo ”

((2[0-4][0-9])|(25[0-5])|([0-1]?[0-9]?[0-9]))

\.((2[0-4][0-9])|(25[1-5])|([0-1]?[0-9]?[0-9]))

\.((2[0-4][0-9])|(25[0-5])|([0-1]?[0-9]?[0-9]))

\.((2[0-4][0-9])|(25[0-5])|([0-1]?[0-9]?[0-9]))”

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

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

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

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

find / -nouser  -o 
-nogroup

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

find /  \( -nouser 
-o  -nogroup \) -a -atime -3

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

find /etc/
-perm -222 -ls

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

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

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

find /etc/init.d/ -perm -446

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

find /usr/ -not  \( -user 
root -o -user bin -o -user hadoop \) -ls

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

 find /etc/ -not -perm -222 -ls

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

find /etc/ -not \(
-user root -o -user hadoop \) -a -mtime -7

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

(0)
haoyphaoyp
上一篇 2017-02-20
下一篇 2017-02-20

相关推荐

  • 实验:配额、RAID、LVM

    实验:在centos7实现光盘yum源 1yum install autofs 2现在启动systemctl start autofs 3开机启动systemctl enable autofs 4 cat /etc/yum.repos.d/base.repo[centos7]name=centos7 repobaseurl=file:///misc/cdgp…

    Linux干货 2017-04-25
  • Linux网络命令学习

    Linux网络命令之网络环境查看命令:ifconfig:查看与配置网络状态命令(只能看到IP地址和子网掩码)ifup 网卡设备名:启用该网卡设备,如:ifup eth0和ifdown lonetstat 选项:  -t:列出TCP协议端口  -u:列出UDP协议端口  -l:仅列出在监听状态网络服务  -a:查看所有连…

    Linux干货 2017-06-25
  • 马哥教育网络版21班第四周作业

    1、复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其他用户均没有任何访问权限 [root@localhost ~]# cp -rf /etc/skel/ /home/tuser1 [root@localhost ~]# chmod&n…

    Linux干货 2016-08-05
  • 编译安装dropbear

    ssh协议的另一个实现:dropbear 编译安装dropbear [root@centos6 ~]# tar xf dropbear-2013.58.tar.bz2  [root@centos6 ~]# cd dropbear-2013.58 [root@centos6&nbs…

    Linux干货 2016-09-28
  • Linux GNU AWK使用

                                    Linux GNU AWK使用 本章内容: awk介绍 awk基本用法 awk变量 awk格式化 awk操作符 awk条件判断…

    系统运维 2016-10-01
  • 第二周作业

    一、文件管理命令以及演示方法  1.1. mkdir命令     作用:创建文件夹     基本用法:mkdir [OPTION]… DIRECTORY…     参数:   &nbsp…

    Linux干货 2016-08-22

评论列表(1条)

  • 马哥教育
    马哥教育 2017-03-06 19:14

    第6个问题可以加上-o 试试