Ack- 类似grep一样的查找
语法
ack [options] PATTERN [FILE...]
ack -f [options] [DIRECTORY...]
介绍
Ack设计可以替代99%grep的功能。
Ack查找给定正则表达式模式的输入文件默认打印匹配的行。
Ack 也能列出文件不真正进行查找,利用文件类型过滤的优势。
文件的选择
ack 只能进行文件查找。 它知道某些类型的文件,基于文件扩展和文件内容。
文件类型的选择可以基于-type选项。
没有文件选择的选项,ack 仅仅查找认识的文件类型。 如果有一个文件名字是foo.wango ,ack将不查找该文件。
-a 选项选择所有文件,无论类型。
一些文件即使-a选项也不进行查找。
•Backup files: Files matching #*# or ending with ~. •Coredumps: Files matching core.\d+
然而,ack需要搜索所有类型的文件,可以通过使用-u选项。
目录的选择
ack 递归搜索目录树。 然而忽略影子目录(很多用于版本控制的目录). 你可以通过添加和移除
--[no]ignore-dir选项。选项可以设置多个目录在忽略或添加的目录中。
选项
-a, --all 操作所有文件,无论类型(但是仍然越过blib,cvs等文件) -A NUM, --after-context=NUM 打印匹配内容后的指定行(选定行也显示) -B NUM, --before-context=NUM 打印匹配内容前的指定行(选定行也显示) -C [NUM], --context[=NUM] 打印匹配行上下的几行(选定行也显示) -c, --count 打印每个文件匹配的行数。 如果有-l选项仅仅显示文件匹配的行数 与-h 匹配显示所有文件匹配的总数 Searching: -i, --ignore-case Ignore case distinctions in PATTERN --[no]smart-case Ignore case distinctions in PATTERN, only if PATTERN contains no upper case Ignored if -i is specified -v, --invert-match Invert match: select non-matching lines -w, --word-regexp Force PATTERN to match only whole words -Q, --literal Quote all metacharacters; PATTERN is literal Search output: --line=NUM Only print line(s) NUM of each file -l, --files-with-matches Only print filenames containing matches -L, --files-without-matches Only print filenames with no matches -o Show only the part of a line matching PATTERN (turns off text highlighting) --passthru Print all lines, whether matching or not --output=expr Output the evaluation of expr for each line (turns off text highlighting) --match PATTERN Specify PATTERN explicitly. -m, --max-count=NUM Stop searching in each file after NUM matches -1 Stop searching after one match of any kind -H, --with-filename Print the filename for each match -h, --no-filename Suppress the prefixing filename on output -c, --count Show number of lines matching per file --column Show the column number of the first match -A NUM, --after-context=NUM Print NUM lines of trailing context after matching lines. -B NUM, --before-context=NUM Print NUM lines of leading context before matching lines. -C [NUM], --context[=NUM] Print NUM lines (default 2) of output context. --print0 Print null byte as separator between filenames, only works with -f, -g, -l, -L or -c. File presentation: --pager=COMMAND Pipes all ack output through COMMAND. For example, --pager="less -R". Ignored if output is redirected. --nopager Do not send output through a pager. Cancels any setting in ~/.ackrc, ACK_PAGER or ACK_PAGER_COLOR. --[no]heading Print a filename heading above each file's results. (default: on when used interactively) --[no]break Print a break between results from different files. (default: on when used interactively) --group Same as --heading --break --nogroup Same as --noheading --nobreak --[no]color Highlight the matching text (default: on unless output is redirected, or on Windows) --[no]colour Same as --[no]color --color-filename=COLOR --color-match=COLOR --color-lineno=COLOR Set the color for filenames, matches, and line numbers. --flush Flush output immediately, even when ack is used non-interactively (when output goes to a pipe or file). File finding: -f Only print the files found, without searching. The PATTERN must not be specified. -g REGEX Same as -f, but only print files matching REGEX. --sort-files Sort the found files lexically. --invert-file-match Print/search handle files that do not match -g/-G. --show-types Show which types each file has. File inclusion/exclusion: -a, --all-types All file types searched; Ignores CVS, .svn and other ignored directories -u, --unrestricted All files and directories searched --[no]ignore-dir=name Add/Remove directory from the list of ignored dirs -r, -R, --recurse Recurse into subdirectories (ack's default behavior) -n, --no-recurse No descending into subdirectories -G REGEX Only search files that match REGEX --perl Include only Perl files. --type=perl Include only Perl files. --noperl Exclude Perl files. --type=noperl Exclude Perl files. See "ack --help type" for supported filetypes. --type-set TYPE=.EXTENSION[,.EXT2[,...]] Files with the given EXTENSION(s) are recognized as being of type TYPE. This replaces an existing definition for type TYPE. --type-add TYPE=.EXTENSION[,.EXT2[,...]] Files with the given EXTENSION(s) are recognized as being of (the existing) type TYPE --[no]follow Follow symlinks. Default is off. Directories ignored by default: autom4te.cache, blib, _build, .bzr, .cdv, cover_db, CVS, _darcs, ~.dep, ~.dot, .git, .hg, _MTN, ~.nib, .pc, ~.plst, RCS, SCCS, _sgbak and .svn Files not checked for type: /~$/ - Unix backup files /#.+#$/ - Emacs swap files /[._].*\.swp$/ - Vi(m) swap files /core\.\d+$/ - core dumps /[.-]min\.js$/ - Minified javascript files Miscellaneous: --noenv Ignore environment variables and ~/.ackrc --help This help --man Man page --version Display version & copyright --thpppt Bill the Cat
文件类型
--[no]actionscript .as .mxml --[no]ada .ada .adb .ads --[no]asm .asm .s --[no]batch .bat .cmd --[no]binary Binary files, as defined by Perl's -B op (default: off) --[no]cc .c .h .xs --[no]cfmx .cfc .cfm .cfml --[no]clojure .clj --[no]cpp .cpp .cc .cxx .m .hpp .hh .h .hxx --[no]csharp .cs --[no]css .css --[no]delphi .pas .int .dfm .nfm .dof .dpk .dproj .groupproj .bdsgroup .bdsproj --[no]elisp .el --[no]erlang .erl .hrl --[no]fortran .f .f77 .f90 .f95 .f03 .for .ftn .fpp --[no]go .go --[no]groovy .groovy .gtmpl .gpp .grunit --[no]haskell .hs .lhs --[no]hh .h --[no]html .htm .html .shtml .xhtml --[no]java .java .properties --[no]js .js --[no]jsp .jsp .jspx .jhtm .jhtml --[no]lisp .lisp .lsp --[no]lua .lua --[no]make Makefiles (including *.mk and *.mak) --[no]mason .mas .mhtml .mpl .mtxt --[no]objc .m .h --[no]objcpp .mm .h --[no]ocaml .ml .mli --[no]parrot .pir .pasm .pmc .ops .pod .pg .tg --[no]perl .pl .pm .pod .t --[no]php .php .phpt .php3 .php4 .php5 .phtml --[no]plone .pt .cpt .metadata .cpy .py --[no]python .py --[no]rake Rakefiles --[no]ruby .rb .rhtml .rjs .rxml .erb .rake .spec --[no]scala .scala --[no]scheme .scm .ss --[no]shell .sh .bash .csh .tcsh .ksh .zsh --[no]skipped Files, but not directories, normally skipped by ack (default: off) --[no]smalltalk .st --[no]sql .sql .ctl --[no]tcl .tcl .itcl .itk --[no]tex .tex .cls .sty --[no]text Text files, as defined by Perl's -T op (default: off) --[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 .xsl .xslt .ent --[no]yaml .yaml .yml