• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

Linux之ack命令

linux 搞代码 3年前 (2022-03-03) 39次浏览 已收录 0个评论

ack是比grep好用的文本搜寻工具

ack命令装置

> yum install -y ack

命令特点

  • 默认搜寻当前工作目录
  • 默认递归搜寻子目录
  • 疏忽元数据目录,比方.svn,.git,CSV等目录
  • 疏忽二进制文件(比方pdf,image,coredumps)和备份文件(比方foo~,*.swp)
  • 在搜寻后果中打印行号,有助于找到指标代码
  • 能搜寻特定文件类型(比方Perl,C++,Makefile),该文件类型能够有多种文件后缀
  • 高亮搜寻后果
  • 反对Perl的高级正则表达式,比grep所应用GNU正则表达式更有表现力。

相比于搜寻速度,ack总体上比grep更快。ack的速度只有体现在它的内置的文件类型过滤器。在搜寻过程中,ack维持着认可的文件类型的列表,同时跳过未知或不必要的文件类型。它同样防止查看多余的元数据目录。

命令参数

  • -n, 显示行号
  • -l/L, 显示匹配/不匹配的文件名
  • -c, 统计次数
  • -v, invert match
  • -w, 词匹配
  • -i, 疏忽大小写
  • -f, 只显示文件名,不进行搜寻.
  • -h, 不显示名称
  • -v, 显示不匹配

在当前目录递归搜寻单词”eat”,不匹配相似于”feature”或”eating”的字符串:

> ack -w eat

搜寻有特殊字符的字符串’$path=.’,所有的元字符(比方’$’,’.’)须要在字面上被匹配:

> ack -Q '$path=.' /etc

除了temp目录,在所有目录搜寻use单词

> ack use --ignore-dir=temp

只搜寻蕴含’main’单词的Python文件,而后通过文件名把搜寻后果整合在一起,打印每个文件对应的搜寻后果

> ack  --python  --group -w main

ack反对的文件类型

> ack --help-types

--[no]actionscript .as .mxml
    --[no]ada          .ada .adb .ads
    --[no]asm          .asm .s
    --[no]asp          .asp
    --[no]aspx         .master .ascx .asmx .aspx .svc
    --[no]batch        .bat .cmd
    --[no]cc           .c .h .xs
    --[no]cfmx         .cfc .cfm .cfml
    --[no]clojure      .clj .cljs .edn .cljc
    --[no]cmake        CMakeLists.txt; .cmake
    --[no]coffeescript .coffee
    --[no]cpp          .cpp .cc .cxx .m .hpp .hh .h .hxx
    --[no]csharp       .cs
    --[no]css          .css
    --[no]dart         .dart
    --[no]delphi       .pas .int .dfm .nfm .dof .dpk .dproj .groupproj .bdsgroup .bdsproj
    --[no]elisp        .el
    --[no]elixir       .ex .exs
    --[no]erlang       .erl .hrl
    --[no]fortran      .f .f77 .f90 .f95 .f03 .for .ftn .fpp
    --[no]go           .go
    --[no]groovy       .groovy .gtmpl .gpp .grunit .gradle
    --[no]gsp          .gsp
    --[no]haskell      .hs .lhs
    --[no]hh           .h
    --[no]hpp          .hpp .hh .h .hxx
    --[no]html         .htm .html .xhtml
    --[no]jade         .jade
    --[no]java         .java .properties
    --[no]js           .js
    --[no]json         .json
    --[no]jsp          .jsp .jspx .jspf .jhtm .jhtml
    --[no]kotlin       .kt .kts
    --[no]less         .less
    --[no]lisp         .lisp .lsp
    --[no]lua          .lua; first line matches /^#!.*\blua(jit)?/
    --[no]make         .mk; .mak; makefile; Makefile; Makefile.Debug; Makefile.Release
    --[no]matlab       .m
    --[no]objc         .m .h
    --[no]objcpp       .mm .h
    --[no]ocaml        .ml .mli .mll .mly
    --[no]parrot       .pir .pasm .pmc .ops .pod .pg .tg
    --[no]perl         .pl .pm .pod .t .psgi; first line matches /^#!.*\bperl/
    --[no]perltest     .t
    --[no]php          .php .phpt .php3 .php4 .php5 .phtml; first line matches /^#!.*\bphp/
    --[no]plone        .pt .cpt .metadata .cpy .py
    --[no]python       .py; first line matches /^#!.*\bpython/
    --[no]rake         Rakefile
    --[no]rr           .R
    --[no]rst          .rst
    --[no]ruby         .rb .rhtml .rjs .rxml .erb .rake .spec; Rakefile; first line matches /^#!.*\bruby/
    --[no]rust         .rs
    --[no]sass         .sass .scss
    --[no]scala        .scala
    --[no]scheme       .scm .ss
    --[no]shell        .sh .bash .csh .tcsh .ksh .zsh .fish; first line matches /^#!.*\b(?:ba|t?c|k|z|fi)?sh\b/
    --[no]smalltalk    .st
    --[no]smarty       .tpl
    --[no]sql          .sql .ctl
    --[no]stylus       .styl
    --[no]swift        .swift; first line matches /^#!.*\bswift/
    --[no]tcl          .tcl .itcl .itk
    --[no]tex          .tex .cls .sty
    --[no]ts           .ts .tsx
    --[no]tt           .tt .tt2 .ttml
    --[no]vb           .bas .cls .frm .ctl .vb .resx
    --[no]verilog      .v .vh .sv
    --[no]vhdl         .vhd .vhdl
    --[no]vim          .vim
    --[no]xml          .xml .dtd .xsd .xsl .xslt .ent .wsdl; first line matches /<[?]xml/
    --[no]yaml         .yaml .yml

获取蕴含CFLAG关键字的Makefile的文件名

> ack --make CFLAG

ack查找my.cnf文件

> ack -f /etc/ | ack my.cnf
//或者
> ack -g my.cnf /etc/

原文链接:https://rumenz.com/rumenbiji/&#8230;
微信公众号:入门小站


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:Linux之ack命令
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址