zoukankan      html  css  js  c++  java
  • 文件内容极速搜索工具: silversearcher-ag

    参考

    https://github.com/ggreer/the_silver_searcher

    安装

    yum install epel-release.noarch the_silver_searcher -y
    

    常见操作

    • ag printf
    	Find matches for "printf" in the current directory.
    
    • ag foo /bar/
    	Find matches for "foo" in path /bar/.
    
    • ag – --foo
    Find matches for "--foo" in the current directory. (As with most UNIX command line utilities, "--" is used to signify that the remaining arguments should not be treated as options.)
    
    • ag -G cpio.c size
    在所有文件名为 *cpio.c* 的文件中搜索字串 size.        (-G --file-search-regex PATTERN,       Only search files whose names match PATTERN. 帮助中出现PATTERN项就代表必须使用正则式)
    
    • ag -G cpio.c -w size
    	在所有文件名为 *cpio.c* 的文件中搜索单词 size. 
    
    • ag readme$
    	正则式搜索 readme$
    
    • ag .rb files/
    	在files目录搜索含  .rb  的字串  (所有的 arb,   crb  等等)
    
    • ag -Q .rb files/
    	在files目录搜索含  .rb  的字串  (只匹配 .rb,相当于正则式的  .rb)
    
    • ag DHH -l
    	搜索含有单词 DHH 的所有文件,且只打印处文件名
    
    • ag readme -l -G action
    	在所有文件名为 *action* 的文件中搜索字串 readme,且只打印处文件名
    
    • ag readme -l -G action$
    	在所有文件名为 *action 的文件中搜索字串 readme,且只打印处文件名
    
    • ps -e | ag forego
    	通过管道使用 ag
    
    • –php
    	只搜索php文件
    
    • ag readme -l -G action$ --pager "less -R"
    在所有文件名为 *action 的文件中搜索字串 readme,且只打印处文件名,使用 less来分页。(alias ag="ag $* --pager 'less -R'",这个可以一劳永逸)**加粗样式**
    
    • -B2
    匹配当前行与前两行
    
    • -A2
    匹配当前行与后两行
    
    • -C2
    匹配当前行以及前后2行
    
    • -w
    以word为单位进行匹配
    
    • -U
    忽略版本控制相关隐藏文件:比如 .gitignore .hgignore
    
  • 相关阅读:
    Leetcode:42. Trapping Rain Water
    Leetcode: 41. First Missing Positive
    Leetcode: 40. Combination Sum II
    多项式全家桶
    BZOJ 3878 [AHOI&JSOI2014]奇怪的计算器 (线段树)
    BZOJ 2959 长跑 (LCT+并查集)
    BZOJ 3028 食物 (生成函数+数学题)
    luogu P5504 [JSOI2011]柠檬
    hdu 6399 City Development
    luogu P3826 [NOI2017]蔬菜
  • 原文地址:https://www.cnblogs.com/yldf/p/11900015.html
Copyright © 2011-2022 走看看