ack

A text search tool that is easier to use than grep

Install

# You need to install ack-grep under ubuntu, because in the debian system, the name ack is occupied by other software.
sudo apt-get install ack-grep
# alpine Linux-apk package manager install ack
apk install ack

Parameters

These parameters are used very frequently on Linux, especially if you use vim as an IDE.

-c (statistics)/ -i (ignore size)/ -h (hide name)/
-l (only display file name)/ -n (add line number)/ -v (display mismatch)

Features

The ack official website lists the 5 major selling points of this tool:

Example

When memorizing, it can be roughly divided into these parts:

Searching code search Search output search result processing File presentation File presentation File finding File finding File inclusion/exclusion file filtering

grep common operations

grep -r 'hello_world' # Simple usage
grep '^hello_world' . # Simple regular expression
ls -l | grep .py # Pipe usage

Searching

Simple text search, recursive by default.

ack-grep hello
ack-grep -i hello
ack-grep -v hello
ack-grep -w hello
ack-grep -Q 'hello*'

Search File

Process the search results, such as displaying only one match for a file, or xxx

ack-grep --line=1 # Output the second line of all files
ack-grep -l 'hello' # Contained file name
ack-grep -L 'print' # Non-included file name

File presentation

How are the output results displayed? There are several parameters in this part that you can practice with.

ack-grep hello --pager='less -R' # Display in less format
ack-grep hello --noheading # Do not display files in the header
ack-grep hello --nocolor # Do not color matching characters

File finding

Yes, it can find files to save you the trouble of constantly combining find and grep, although the idea in Linux is that a tool does one thing well.

ack-grep -f hello.py # Find all matching files
ack-grep -g hello.py$ # Find regular matching files
ack-grep -g hello --sort-files # Search and sort

File inclusion/exclusion

File filtering, I personally think this is a very good feature. You may find this useful if you have ever accidentally hit a keyword in the log while searching for project source code.

ack-grep --python hello # Find all python files
ack-grep -G hello.py$ hello # Find files matching regular patterns

References