马哥教育网络20期+第五周练习博客

作业要求:

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

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

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

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

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

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

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

        扩展:取出其路径名

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

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

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

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

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

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

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

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

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

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

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

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


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

[root@localhost /]# grep "^[[:space:]]\+" /boot/grub/grub.conf 
	root (hd0,0)
	kernel /vmlinuz-2.6.32-504.el6.x86_64 ro root=UUID=aa5cf6b3-e1b5-4eb2-95e6-e202f2890edf rd_NO_LUKS rd_NO_LVM LA
NG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet	initrd /initramfs-2.6.32-504.el6.x86_64.img

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

[root@localhost /]# grep "^#[[:space:]]\+[^[:space:]]" /etc/rc.d/rc.sysinit

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

[root@localhost /]# netstat -tan | grep "LISTEN[[:space:]]*$"
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      
tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      
tcp        0      0 :::22                       :::*                        LISTEN      
tcp        0      0 ::1:631                     :::*                        LISTEN      
tcp        0      0 ::1:25                      :::*                        LISTEN      
[root@localhost /]#

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

[root@localhost /]# grep -E '^(\<[a-z]+\>).*\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
nologin:x:501:501::/home/nologin:/sbin/nologin
bash:x:502:502::/home/bash:/bin/bash
[root@localhost /]#

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

[root@localhost /]# grep -E '^(root|fedora|user1)' /etc/passwd
root:x:0:0:root:/root:/bin/bash
[root@localhost /]#

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

[root@localhost /]# grep -E "[a-z]+\(\)" /etc/rc.d/init.d/functions

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

        扩展:取出其路径名

[root@localhost network-scripts]# echo /etc/sysconfig/network-scripts | grep -o "[^/]*$"
network-scripts
[root@localhost network-scripts]# echo /etc/sysconfig/network-scripts | grep -oP "^.*(?=/)"
/etc/sysconfig
[root@localhost network-scripts]#

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

[root@localhost ~]# ifconfig | egrep -o "[1-9]{1,2}|2[0-5]{1,2}"

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

[root@localhost ~]# ifconfig | egrep -o "[1-9]{1,3}\.[1-9]{1,3}\.[1-9]{1,3}\.[1-9]{1,3}" 
192.168.1.8
192.168.1.255
192.168.1.25
192.168.253.135
192.168.253.255
192.168.253.25
[root@localhost ~]# 

备注:这写法会匹配888.888.888.888之类的数字,但是ifconfig的结果中以点分十进制数字中不会出现此类数字!!偷懒的写法

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

 [root@localhost ~]# cat mail.txt  | grep '[[:alnum:]]\+@[[:alnum:]]\+\.[[:alnum:]]\+$' 
mfchangs@126.com
mfchangs@sina.com
mfchangs@qq.com
mfchangs100@sina.com
[root@localhost ~]# cat mail.txt 
123456@adadf
mfchangs@126.com
mfchangs@sina.com
mfchangs@qq.com
akjdflajf@qqajdlaflk
mfchangs100@sina.com
[root@localhost ~]#

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

[root@localhost ~]# find  /var -user root -group mail 
/var/spool/mail
/var/spool/mail/root
[root@localhost ~]#

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

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

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

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

[root@localhost ~]# find /etc -perm -222 -ls

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

[root@localhost ~]#  find /etc -type f -size +1M -ls
668012 7892 -rw-r--r--   1 root     root      8080653 Jul  4 08:37 /etc/selinux/targeted/modules/active/policy.kern
668019 7892 -rw-r--r--   1 root     root      8080653 Jul  4 08:37 /etc/selinux/targeted/policy/policy.24
794284 1976 -rw-r--r--   1 root     root      2020885 Jul  4 08:34 /etc/gconf/gconf.xml.defaults/%gconf-tree.xml
[root@localhost ~]#

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

[root@localhost ~]# find /etc/init.d/ -type f -perm -102 -ls
663307    0 -rwxrwxrwx   1 root     root            0 Jul  9 17:20 /etc/init.d/test.txt

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

[root@localhost ~]# touch /usr/2.txt
[root@localhost ~]# chown test:test /usr/2.txt
[root@localhost ~]# find /usr/ -type f !  \( -user  root -o -user bin -o -user hadoop \) -ls
400099   12 -rwsr-xr-x   1 abrt     abrt        10296 Oct 16  2014 /usr/libexec/abrt-action-install-debuginfo-to-abrt-cache
395439    0 -rw-r--r--   1 test     test            0 Jul  9 17:29 /usr/2.txt
[root@localhost ~]#

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

[root@localhost ~]# find /etc/ ! -perm +222 -ls

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

[root@localhost ~]# find /etc/ -type f -ctime -7  -a ! \( -user root -o -user hadoop \) -ls
663346    4 -rw-r--r--   1 test     test            2 Jul  9 17:37 /etc/2.txt
[root@localhost ~]#





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

赞 (0)
Net20-deamonNet20-deamon
上一篇 2016-07-09 17:01
下一篇 2016-07-10 01:03

相关推荐

  • 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干货 2016-11-02
  • 安全及数字认证等使用

    偏重实现ca数字认证及实现基于key的登录

    2018-05-19
  • Linux第九周总结

    1、写一个脚本,判断当前系统上所有用户的shell是否为可登录shell(即用户的shell不是/sbin/nologin);分别这两类用户的个数;通过字符串比较来实现; #!/bin/bash # login_user=0 nologin_user=0 for i in $(cat /etc/passwd | cut -d : -f 7);do &nbsp…

    Linux干货 2017-08-28
  • 基于pxe部署系统

    一、前言 在生产环境中,我们经常遇到需要部署部署多台服务器。如果我们每部署一台服务器都要拿着系统盘到机房部署,守在服务器面前,那么我们的效率是十分低下的。况且有时候机房并不在我们身边。那么我们可以通过让机房值班人员为每台服务器配置好远程管理卡,运维人员通过远程管理卡,远程登入服务器进行操作。 二、pxe原理 pxe原理是通过服务器上网卡中支持的pxe启动,通…

    Linux干货 2015-09-14
  • 马哥教育网络班22期+第七周课程练习

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

    Linux干货 2016-11-07
  • M22 Centos设置yum源方法

    实验目的: 使用虚拟机模拟建立yum源服务器,在客户机上指定yum源为该服务器。 实验器材: WMware12安装Centos6.8虚拟机作为yum服务源 WMware12安装Centos7.3 作为客户端访问yum源服务器 实验原理图: 实验过程: 服务器端: 1、  显示已经挂载的光盘 #cd /misc/cd #先执行此命令才可以看到光盘挂载…

    2017-03-06

评论列表(1条)

  • 马哥教育
    马哥教育 2016-07-12 14:45

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