文本过滤、文本查找工具应用示例

文本过滤、文本查找工具应用示例

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

    [root@localhost ~]# cat /etc/passwd|grep "^root\>\|^fedora\>\|^user1\>"|cut -d: -f7
      /bin/bash
      /bin/bash
      /bin/bash
  • 2.找出/etc/rc.d/init.d/functions文件中某个单词后面跟一组小括号的行,形如:hello()

    [root@localhost ~]# cat /etc/rc.d/init.d/functions|grep -o "[[:alpha:]]\+\>()"
     checkpid()
     checkpids()
     kill()
     run()
     pidof()
     daemon()
     killproc()
     pidfileofproc()
     pidofproc()
     status()
     success()
     failure()
     passed()
     warning()
     stage()
     success()
     failure()
     passed()
     warning()
     action()
     strstr()
     file()
     true()
     false()
     sysctl()
  • 3.使用echo命令输出一个绝对路径,使用grep取出其基名;扩展,取出其路径名

    [root@localhost ~]# echo "/etc/rc.d/init.d/functions"|grep -o  "[^\/]\+\/\?$"
     functions
    [root@localhost ~]# echo "/etc/rc.d/init.d/functions"|grep -o  "^\/[^[:space:]]\+\/"
     /etc/rc.d/init.d/
  • 4.找出ifconfig命令结果中1-255之间的数字

    [root@localhost ~]# ifconfig|grep  -E  -o "([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])"
    33
    41
    63
    150
    192
    168
    91
    128
    255
    255
    255
    192
    168
    91
    255
    6
    80
  • 5.挑战题:写一个模式,能匹配合理的IP地址

    [root@localhost ~]# ifconfig|grep  -E  -o "([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])"
     192.168.91.128
     192.168.91.255
     192.168.122.1
     192.168.122.255
  • 6.挑战题:写一个模式,能匹配所有的邮件地址

    [root@localhost ~]# echo "1234567nn@163.com"|grep -o "[[:alnum:]]\+@[[:alnum:]]\+\.[[:alpha:]]\+"
     1234567nn@163.com
  • 7.查找/var目录下属主为root,且属组为mail的所有文件或目录

    [root@localhost ~]# find /var -user root -a -group mail -ls
     67292968    0 drwxrwxr-x   2 root     mail          129 Jul 28 18:28 /var/spool/mail
  • 8.查找当前系统上没有属主或属组的文件;进一步查找当前系统上没有属主或属组,且最近3天内曾经被访问过的文件或目录

    [root@localhost ~]# find / -nouser  -a -nogroup  -ls
    [root@localhost ~]# find / -nouser  -a -nogroup -a -atime -3  -ls
  • 9.查找/etc目录下所有用户都有写权限的文件

    [root@localhost ~]# find /etc -perm -222 -ls
     33554500    0 lrwxrwxrwx   1 root     root           17 Jun 30 01:53 /etc/mtab -> /proc/self/mounts
     35553953    0 lrwxrwxrwx   1 root     root           56 Jun 30 02:10 /etc/fonts/conf.d/65-0-lohit-marathi.conf -> /usr/share/fontconfig/conf.avail/65-0-lohit-marathi.conf
     33722185    0 lrwxrwxrwx   1 root     root           56 Jun 30 01:57 /etc/fonts/conf.d/59-liberation-mono.conf -> /usr/share/fontconfig/conf.avail/59-liberation-mono.conf
     35553954    0 lrwxrwxrwx   1 root     root           59 Jun 30 02:10 /etc/fonts/conf.d/65-0-lohit-devanagari.conf -> /usr/share/fontconfig/conf.avail/65-0-lohit-devanagari.conf
     33722192    0 lrwxrwxrwx   1 root     root           56 Jun 30 01:57 /etc/fonts/conf.d/59-liberation-sans.conf -> /usr/share/fontconfig/conf.avail/59-liberation-sans.conf
     35553957    0 lrwxrwxrwx   1 root     root           54 Jun 30 02:11 /etc/fonts/conf.d/66-ucs-miscfixed.conf -> /usr/share/fontconfig/conf.avail/66-ucs-miscfixed.conf
     33735545    0 lrwxrwxrwx   1 root     root           59 Jun 30 01:57 /etc/fonts/conf.d/10-scale-bitmap-fonts.conf -> /usr/share/fontconfig/conf.avail/10-scale-bitmap-fonts.conf
     35553958    0 lrwxrwxrwx   1 root     root           50 Jun 30 02:11 /etc/fonts/conf.d/60-open-sans.conf -> /usr/share/fontconfig/conf.avail/60-open-sans.conf
  • 10.查找/etc目录下大于1M,且类型为普通文件的所有文件

    [root@localhost ~]# find /etc -size +1M -a -type f -ls
     102108754 1364 -rw-r--r--   1 root     root      1394978 Jul  9 05:37 /etc/selinux/targeted/contexts/files/file_contexts.bin
     68163210 3620 -rw-r--r--   1 root     root      3703887 Jul  9 05:37 /etc/selinux/targeted/policy/policy.30
     68163206 3620 -rw-r--r--   1 root     root      3703887 Jul  9 05:37 /etc/selinux/targeted/active/policy.kern
     68112876 7120 -r--r--r--   1 root     root      7289802 Jul  9 05:33 /etc/udev/hwdb.bin
     34410868 1336 -rw-r--r--   1 root     root      1367395 Nov  5  2016 /etc/brltty/zh-tw.ctb

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

(0)
N27_xiaoniN27_xiaoni
上一篇 2017-07-30 21:21
下一篇 2017-07-30 21:53

相关推荐

  • LVM逻辑卷管理练习

         小编今天要讲的内容是如何创建逻辑卷,然后扩展它、缩减它。LVM 的重点就在于可以弹性的调整文件系统的容量!所以,下面练习开始。 1、创建一个至少有两个PV组成的大小为20G的名为testvg的 VG;要求PE大小为16MB, 而后在卷组中创建大小为5G的逻 辑卷testlv;挂载至/users目录。 ①准备两个10G的…

    2017-08-26
  • heartbeat实现高可用集群(2)

    [[ heartbeat v2 + crm ]] 环境 node1 192.168.1.35 node2 192.168.1.36 fip 192.168.1.81 daemon httpd ha web service ip httpd node1&2 # vim ha.cf crm on # cd # rpm -ivh heartbeat-gui…

    Linux干货 2017-11-03
  • 单引号、双引号和反引号使用方法

        首先向马哥和马哥团队敬个礼,谢谢你们带我进入Linux的世界,刚开始接触linux时,经常看到单引号、双引号和反引号特殊符号,经常搞混淆和误用,应该用双引号,有时用到单引号。经过几天的混乱引用,总算搞明白了一些,简单总一下三者的使用和区别。  单引号 ‘’     单引号里的内容全部以普通字符的含义进…

    Linux干货 2015-07-29
  • HA高可用集群学习笔记

    前言   什么是HA?HA做什么用的?   HA(High Available)是高可用集群,是保证业务不中断性的有效解决方案;通常HA集群部署在多个节点,正在提供服务的节点成为活动节点,没有提供服务的是非活动节点;当活动节点发生故障,非活动节点会转为活动节点,向外提供服务,以保证业务的连续性;这就是HA。 一、HA(High Avail…

    Linux干货 2015-06-30
  • Windows PHP 中 VC6 X86 和 VC9 X86 的区别及 Non Thread Safe 的意思

    PHP5.3以后 For Windows 提供了四个版本VC9 x86 Non Thread Safe、VC9 x86 Thread Safe、VC6 x86 Non Thread Safe、VC6 x86 Thread Safe 在 官网 左边栏有提示: Which version do I choose? If you are usi…

    Linux干货 2015-06-16

评论列表(1条)

  • 马哥教育
    马哥教育 2017-08-04 16:15

    文本管理工具是非常重要的一项技能,从作业情况来看,掌握的还不错,继续努力。