linux 上查找包含特定文本的所有文件
        【摘要】  grep> grep -rnw '/path/to/somewhere/' -e 'pattern'-r或者-R是递归的,-n 是行号,并且-w 代表匹配整个单词。-l (小写 L) 可以添加只给出匹配文件的文件名。-e 是搜索过程中使用的模式除了这些, --exclude, --include,–exclude-dir标志可用于高效搜索: 只搜索那些具有 .c 或 .h 扩展名的文件> ...
    
    
    
    grep
> grep -rnw '/path/to/somewhere/' -e 'pattern'
 
 - -r或者-R是递归的,
 - -n 是行号,并且
 - -w 代表匹配整个单词。
 - -l (小写 L) 可以添加只给出匹配文件的文件名。
 - -e 是搜索过程中使用的模式
 
除了这些, --exclude, --include,–exclude-dir标志可用于高效搜索:
只搜索那些具有 .c 或 .h 扩展名的文件
> grep --include=\*.{c,h} -rnw '/path/to/somewhere/' -e "pattern"
 
 排除搜索所有以 .o 扩展名结尾的文件:
> grep --exclude=\*.o -rnw '/path/to/somewhere/' -e "pattern"
 
  对于目录,可以使用–exclude-dir参数排除一个或多个目录。例如,这将排除目录dir1/、dir2/ 以及所有与*.dst/ 匹配的目录
 
 > grep --exclude-dir={dir1,dir2,*.dst} -rnw '/path/to/somewhere/' -e "pattern"
 
 ack
> awk "/root/" /etc/passwd
 
 find
> find / -type f -exec grep -l "rumenz" {} \; 
> find . -name "*.txt" | xargs grep -i "rumenz"
 
 别名一个ffind
在~/.bashrc文件中
> alias ffind find / -type f | xargs grep
 
 启动一个新终端
> ffind 'rumenz'
 
 ack-grep
> ack-grep "rumenz"
 
 ack
> ack -i rumenz doc/*
 
 git 存储库中查找
> git grep "rumenz"
 
 原文链接:https://rumenz.com/rumenbiji/linux-find-strings.html
 微信公众号:入门小站
            【声明】本内容来自华为云开发者社区博主,不代表华为云及华为云开发者社区的观点和立场。转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息,否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
                cloudbbs@huaweicloud.com
                
            
        
        
        
        
        
        
        - 点赞
 - 收藏
 - 关注作者
 
            
           
评论(0)