N22- 第五周

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

[root@localhost Packages]# grep -E "^(root|fedora|user1\>)" /etc/passwd | cut -d: -f 1,7
root:/bin/bash
fedora:/vin/zsh
user1:/bin/bash

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

[root@localhost Packages]# grep -E "\<[a-z]*\>\(\)" /etc/rc.d/init.d/functions 
checkpid() {
daemon() {
killproc() {
pidfileofproc() {
pidofproc() {
status() {
success() {
failure() {
passed() {
warning() {
action() {
strstr() {

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

[root@localhost ~]# echo /etc/sysconfig/network-scripts/ | grep -E -o '^/.*[^/]' | grep -E -o '[^/]+/?$'
network-scripts

    扩展:取出其路径名

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


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

[root@localhost ~]# ifconfig | grep -E -o '\([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-5][0-5]\)'
167
77
73
41
63
150
192
168

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

[root@localhost ~]# ifconfig | grep -E -o "\<([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\>.\<([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\>.\<([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\>.\<([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\>"
192.168.8.233
192.168.8.255

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

[root@localhost scripts]# grep -E -o '[^[:space:]]+@[^[:space:]]+\.com'  mail.txt 
123434@163.com
steph_fase@163.com
sdf2121_fsdf@sohu.com

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

[root@localhost tmp]# find /var -user root -group mail -ls 
201327614    0 drwxrwxr-x   2 root     mail           67 Nov 15 13:24 /var/spool/mail

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

[root@localhost tmp]# find / \( -nouser -o -nogroup \) -ls
 46767   35 -rw-rw-r--   1 502      502         35380 Jul  4  2014 /mnt/dvd/Packages/zziplib-utils-0.13.62-5.el7.x86_64.rpm
 46771  137 -rw-rw-r--   1 502      502        140092 Jul  4  2014 /mnt/dvd/Packages/zziplib-devel-0.13.62-5.el7.x86_64.rpm
 46776  137 -rw-rw-r--   1 502      502        140088 Jul  4  2014 /mnt/dvd/Packages/zziplib-devel-0.13.62-5.el7.i686.rpm
 46784   82 -rw-rw-r--   1 502      502         83176 Jul  4  2014 /mnt/dvd/Packages/zziplib-0.13.62-5.el7.x86_64.rpm
 46788   82 -rw-rw-r--   1 502      502         83640 Jul  4  2014 /mnt/dvd/Packages/zziplib-0.13.62-5.el7.i686.rpm

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

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

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

[root@localhost tmp]# find /etc -perm -222 -type f -ls

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

[root@localhost tmp]# find /etc/ -size +1M -type f -ls 
2155134 6228 -r--r--r--   1 root     root      6376691 Aug 25 10:12 /etc/udev/hwdb.bin
137800582 1364 -rw-r--r--   1 root     root      1395438 Jun 10  2014 /etc/gconf/schemas/ekiga.schemas

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

[root@localhost init.d]# find /etc/init.d/ -perm -113 -ls 
  8316    0 ---x--x-wx   1 root     root            0 Nov 17 11:13 /etc/init.d/a

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

[root@localhost init.d]# find /usr -not \( -user root -o -user bin -o -user hadoop \) -ls  
1431384    4 drwx------   2 polkitd  root         4096 Aug 25 10:18 /usr/share/polkit-1/rules.d

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

[root@localhost init.d]# find /etc/ -perm -111 -type f -ls

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

[root@localhost init.d]# find /etc -mtime -7 -a -not \( -user root -o -user hadoop \) -ls





原创文章,作者:N22-成都-stephen,如若转载,请注明出处:http://www.178linux.com/59550

(0)
N22-成都-stephenN22-成都-stephen
上一篇 2016-11-21
下一篇 2016-11-21

相关推荐

  • vncserver安装配置小结

      安装VNC Server 端:        1. yum install  tigervnc-server         //RHEL6: vnc server的包名          yum &nbs…

    Linux干货 2016-03-09
  • 修改Linux命令终端提示符

    作业1. 设置自己的终端提示符,要求字符终端登录时:     a> 需要带颜色     b> 需要显示当前执行到了第几条命令     c> 显示当前登录终端,主机名和当前时间     这可以通…

    Linux干货 2016-10-17
  • Linux基础知识(五)

    本文主要讲述使用grep做模式匹配,具体示例包括: 1、显示/boot/grub/grub.conf中以至少一个空白字符开头的行; 2、显示/etc/rc.d/rc.sysinit文件中以#开头,后面跟至少一个空白字符,而后又有至少一个非空白字符的行; 3、打出netstat -tan命令执行结果中以‘LISTEN’,后或跟空白字符结尾的行; 4、添加用户b…

    Linux干货 2016-10-23
  • SElinux配置httpd

    一、启用SELinux策略并安装httpd服务,改变网站的默认主目录为/website,添加SELinux文件标签规则,使网站可访问     1、修改selinux策略并重启 [root@localhost ~]# vim /etc/selinux/config# This file controls the stat…

    Linux干货 2016-09-19
  • N26 第七周作业

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

    Linux干货 2017-02-07

评论列表(1条)

  • luoweiro
    luoweiro 2016-11-29 22:50

    作业完成的还算不错,有拓展和挑战,如果有自己对grep的基础总结就会更好了,加油。