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

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

[root@localhost /]# grep '^[[:space:]]\+' /boot/grub/grub.conf

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

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

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

[root@localhost /]# netstat -tan | grep '.*LISTEN[[:space:]]\+$'

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

[root@localhost ~]# useradd bash
[root@localhost ~]# useradd testbash
[root@localhost ~]# useradd basher
[root@localhost ~]# useradd -s /sbin/nologin nologin
[root@localhost ~]# cat /etc/passwd | grep '^\([[:alnum:]]\+\)\:.*\1$'
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:501:501::/home/bash:/bin/bash
nologin:x:504:504::/home/nologin:/sbin/nologin

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

[root@localhost ~]# egrep '^(root|fedora|user1)' /etc/passwd

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

[root@localhost ~]# grep '.*\([[:alpha:]]\+\)().*' /etc/rc.d/init.d/functions

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

[root@localhost ~]# echo /etc/sysconfig/network-scripts/ifcfg-eth0 | grep -o '[^\/]\+$'

扩展:取出其路径名

[root@localhost ~]# echo /etc/sysconfig/network-scripts/ifcfg-eth0 | grep -o '^\/.*\/'

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

[root@localhost ~]# ifconfig | egrep -o '\<([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\>'

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

[root@localhost ~]# ifconfig | egrep -o '[1-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'
192.168.206.134
192.168.206.255
255.255.255.0
127.0.0.1
255.0.0.0

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

[root@localhost ~]# cat mail.txt | grep '.*@.*\.[[:alpha:]]\+$'
woeir@sina.com
oqwje@qq.com
ooqwe@123.net

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

[root@localhost ~]# find /var -group mail -uid 0 -ls
398910    4 drwxr-xr-x   2 root     mail         4096 Aug  2 08:21 /var/maillist
924654    0 -rw-r--r--   1 root     mail            0 Aug  2 08:18 /var/mail.txt
1042463    4 drwxrwxr-x   2 root     mail         4096 Aug  1 05:11 /var/spool/mail
1057928    4 -rw-------   1 root     mail         1336 Aug  1 05:11 /var/spool/mail/root

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

[root@localhost ~]# find / -nouser -o -nogroup -ls

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

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

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

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

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

[root@localhost ~]# find /etc -size +1M -type f 
/etc/gconf/gconf.xml.defaults/%gconf-tree.xml
/etc/selinux/targeted/policy/policy.24
/etc/selinux/targeted/modules/active/policy.kern

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

[root@localhost ~]# find /etc/init.d/ -perm -113

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

[root@localhost ~]# find /usr/ -not \( -user root -o -user bin -o -user hadoop \) -ls

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

[root@localhost ~]# find /etc/ \( -perm +555 -o -perm +444 -o -perm +111 \)

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

[root@localhost ~]# find /etc/ -atime 7 -not \( -user root -o -user hadoop \)

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

(0)
N21-yoyo_chenN21-yoyo_chen
上一篇 2016-08-02 16:24
下一篇 2016-08-02 16:44

相关推荐

  • DNS服务器——如何解析公司域名

    DNS and Bind ·Sockets:          C/S                  Client:…

    Linux干货 2016-09-25
  • week5

    1、显示当前系统上root、fedora或user1用户的默认shell; useradd fedora useradd user1 egrep "^(root|fedora|user1)" /etc/passwd | cut -d: -f1,7 2、找出/e…

    Linux干货 2016-11-24
  • 高考答案

    1、简述TCP三次握手四次挥手过程及各过程中客户端和服务器端的状态。 答:三次握手:        客户端发起连接请求SYN给服务器端        服务器端发送ACK回应及SYN请求给客户端    &nbsp…

    Linux试题 2016-06-18
  • 正则表达式以及Linux文本搜索工具grep

    一正则表达式 regual Expression  简称REGEXP 定义:由一类特殊字符以及文本字所编写的模式,其中有些字符不表示其字面意义,而用于统配和统配功能 分类:     基本正则表达式:BRE 贪婪模式(尽可能长地去匹配符合模式的内容     扩展表达式:E…

    Linux干货 2016-08-07
  • Shell脚本编程

    Shell脚本编程

    2017-09-20
  • N26-第三周博客作业

    1、  列出当前系统上所有已经登录的用户的用户名,注意:同一个用户登录多次,则只显示一次即可。 命令:who | cut -d' ' -f1 | sort –u 涉及知识点: l  who命令 作用:查看当前所有的登录会话 l  cut命令 作用:将文本内容按照指定内容分割,然后取出指定字段。 常用选项: &…

    Linux干货 2017-02-10

评论列表(1条)

  • 马哥教育
    马哥教育 2016-08-02 16:33

    17,18题有问题,需要好好思考一下。