← 返回命令列表

Linux command

ack 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Search

ack [pattern]

Example

ack --type=[perl|python|ruby|js] [pattern]

Example

ack -i [pattern]

Example

ack -l [pattern]

Example

ack -C [3] [pattern]

说明

ack is a code-searching tool designed as an alternative to grep, optimized for programmers. It automatically skips backup files, version control directories (.git, .svn), and binary files while searching recursively through source code. The tool provides built-in file type filtering, allowing searches limited to specific programming languages. Output is formatted with color highlighting and file grouping for easier reading. It uses Perl regular expressions, providing powerful pattern matching capabilities.

参数

-i, --ignore-case
Case insensitive search
-v, --invert-match
Invert the match; select non-matching lines
-w, --word-regexp
Match whole words only
-l, --files-with-matches
Print only filenames containing matches
-L, --files-without-matches
Print filenames that don't contain matches
-c, --count
Print count of matching lines per file
-C _num_, --context=_num_
Print num lines of context around matches
-A _num_, --after-context=_num_
Print num lines after each match
-B _num_, --before-context=_num_
Print num lines before each match
--type=_TYPE_
Search only files of TYPE (perl, python, ruby, js, etc.)
--nocolor
Disable color output
-f
Print files that would be searched (dry run)
--ignore-dir=_name_
Ignore directory name
--help-types
List all recognized file types

FAQ

What is the ack command used for?

ack is a code-searching tool designed as an alternative to grep, optimized for programmers. It automatically skips backup files, version control directories (.git, .svn), and binary files while searching recursively through source code. The tool provides built-in file type filtering, allowing searches limited to specific programming languages. Output is formatted with color highlighting and file grouping for easier reading. It uses Perl regular expressions, providing powerful pattern matching capabilities.

How do I run a basic ack example?

Run `ack [pattern]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -i, --ignore-case do in ack?

Case insensitive search