搜索文件&使用银色搜索器的文件名称 [英] Search for files & file names using silver searcher

查看:159
本文介绍了搜索文件&使用银色搜索器的文件名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Silver Searcher,我该如何搜索:
$ b


  1. (非二进制)带有单词或模式的文件
  2. 所有文件名,包含一个文字或模式,包括二进制文件的文件名。
    $ b

    其他偏好设置:希望通过点文件进行不区分大小写的搜索和搜索。






    尝试别名使用这没有太多的运气:



    alias search =ag -g $ 1 --smart-case --hidden&& ag --smart-case --hidden $ 1

    解决方案

    code> ag

      -G  - 文件搜索regex PATTERN 
    仅搜索名称与PATTERN匹配的文件。

    您可以使用 -G 选项对匹配模式的文件执行搜索。



    所以,要回答你的问题:

    pre $ root $ apache107: 〜/ rpm-4.12.0.1#ag -G cpio.c size
    rpm2cpio.c
    21:off_t payload_size;
    73:/ *检索有效负载大小和压缩类型。 * /
    76:payload_size = headerGetNumber(h,RPMTAG_LONGARCHIVESIZE);

    以上命令搜索单词 size 在与模式 cpio.c



    匹配的所有文件中引用:

    man page ag 版本0.28.0



    注1:



    如果您在某些文件类型中查找字符串,请说出所有C源代码,则有 ag 中的rel =noreferrer>未记录的功能,以帮助您快速限制对某些文件类型的搜索。



    下面的命令都会在所有php文件中查找 foo


    $ b

      find。 -name \ * .php -exec grep foo {} 
    ag --php foo

    虽然 find + grep 会查找所有 .php 文件, - php code> switch在 ag 命令中实际上会查找以下文件扩展名:

      .php .phpt .php3 .php4 .php5 .phtml 

    您可以使用 - cpp 用于C ++源文件, - hh 用于 .h 文件, - js 用于JavaScript等等。完整的列表可以在这里


    Using Silver Searcher, how can I search for:

    1. (non-binary) files with a word or pattern AND
    2. all filenames, with a word or pattern including filenames of binary files.

    Other preferences: would like to have case insensitive search and search through dotfiles.


    Tried to alias using this without much luck:

    alias search="ag -g $1 --smart-case --hidden && ag --smart-case --hidden $1"

    解决方案

    According to the man page of ag

       -G --file-search-regex PATTERN
              Only search files whose names match PATTERN.
    

    You can use the -G option to perform searches on files matching a pattern.

    So, to answer your question:

    root@apache107:~/rpm-4.12.0.1# ag -G cpio.c size
    rpm2cpio.c
    21:    off_t payload_size;
    73:    /* Retrieve payload size and compression type. */
    76:     payload_size = headerGetNumber(h, RPMTAG_LONGARCHIVESIZE);
    

    the above command searches for the word size in all files that matches the pattern cpio.c

    Reference:
    man page of ag version 0.28.0

    Note 1:

    If you are looking for a string in certain file types, say all C sources code, there is an undocumented feature in ag to help you quickly restrict searches to certain file types.

    The commands below both look for foo in all php files:

    find . -name \*.php -exec grep foo {}
    ag --php foo
    

    While find + grep looks for all .php files, the --php switch in the ag command actually looks for the following file extensions:

    .php  .phpt  .php3  .php4  .php5  .phtml
    

    You can use --cpp for C++ source files, --hh for .h files, --js for JavaScript etc etc. A full list can be found here

    这篇关于搜索文件&使用银色搜索器的文件名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆