A text search tool that is better than grep.
# On Ubuntu, install ack-grep, as the name 'ack' is taken by other software in Debian-based systems.
sudo apt-get install ack-grep
# On Alpine Linux using the apk package manager:
apk add ack
These parameters are highly used in Linux, especially if you use Vim as an IDE.
-c (count) / -i (ignore case) / -h (no filename) /
-l (filenames only) / -n (line number) / -v (invert match)
The official ack website lists five main selling points for this tool:
The usage can be roughly categorized into:
Searching
Search output
File presentation
File finding
File inclusion/exclusion
Common grep operations:
grep -r 'hello_world' # Simple recursive search
grep '^hello_world' . # Simple regex
ls -l | grep .py # Pipe usage
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*'
Processing search results, such as showing only filenames.
ack-grep --line=1 # Output the first line of all files
ack-grep -l 'hello' # Filenames that contain the match
ack-grep -L 'print' # Filenames that do NOT contain the match
How the output is displayed. You can practice with these parameters:
ack-grep hello --pager='less -R' # Display using less
ack-grep hello --noheading # Do not show filename headers
ack-grep hello --nocolor # Do not color match strings
Yes, it can find files, saving you the trouble of combining find and grep, even though the Linux philosophy is "one tool for one task."
ack-grep -f hello.py # Find files matching the exact name
ack-grep -g hello.py$ # Find files matching a regex
ack-grep -g hello --sort-files # Find and then sort results
File filtering is a very useful feature. If you've ever accidentally hit a keyword in a log file while searching project source code, you'll find this helpful.
ack-grep --python hello # Search only in Python files
ack-grep -G hello.py$ hello # Search only in files matching the regex