zoukankan      html  css  js  c++  java
  • linux中查找包含特定字符的文件

    1、测试数据

    [root@centos79 test]# ls
    a.txt
    [root@centos79 test]# cat a.txt
    a g e
    u c j alike
    i x k like
    w f g liker
    s g e g
    [root@centos79 test]# echo "b.txt c.txt d.txt" | xargs -n 1 cp a.txt
    [root@centos79 test]# ls
    a.txt  b.txt  c.txt  d.txt
    [root@centos79 test]# md5sum *
    6659dac6dc59934b85df2f6d08c37e9f  a.txt
    6659dac6dc59934b85df2f6d08c37e9f  b.txt
    6659dac6dc59934b85df2f6d08c37e9f  c.txt
    6659dac6dc59934b85df2f6d08c37e9f  d.txt

    2、

    [root@centos79 test]# ls
    a.txt  b.txt  c.txt  d.txt
    [root@centos79 test]# echo "error" >> b.txt
    [root@centos79 test]# echo "ERROR" >> c.txt
    [root@centos79 test]# echo "failed" >> d.txt
    [root@centos79 test]# grep -l "error" *.txt   ## 包含“error”的文件
    b.txt
    [root@centos79 test]# grep -L "error" *.txt  ## 不包含error的文件
    a.txt
    c.txt
    d.txt
    [root@centos79 test]# grep -i -l "error" *.txt  ##忽略大小写,列出包含error的文件
    b.txt
    c.txt
    [root@centos79 test]# grep -i -l -E "error|failed" *.txt  ## 忽略大小写,同时列出包含“error和failed”的文件
    b.txt
    c.txt
    d.txt
    [root@centos79 test]# grep -i -L -E "error|failed" *.txt  ## -L 取反
    a.txt
  • 相关阅读:
    C#学习-多态
    C#学习-子类的初始化顺序
    C#学习-面向对象
    Python数据类型知识点全解
    python 复制图片到剪贴板
    pyperclip
    pyautogui
    多线程代码案例
    常用正则表达式最强整理(速查手册)
    python os
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/14969663.html
Copyright © 2011-2022 走看看