关于linux:Linux之ack命令

3次阅读

共计 2870 个字符,预计需要花费 8 分钟才能阅读完成。

回复【1001】获取 linux 常用命令速查手册

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/…
微信公众号: 入门小站

  • 回复【1001】获取 linux 常用命令速查手册
  • 回复【10010】获取 阿里云 ECS 运维 Linux 系统诊断
  • 回复【10012】获取 Linux 学习笔记【强悍总结值得一看】
  • 回复【10013】获取 shell 扼要教程

正文完
 0