For system administrators or programmers, the grep type tool is probably the most popular when it is necessary to search for a specific text or pattern in a directory of complex configurations or in a large source tree. If grep is one of your favorite tools, you might prefer an ACK. ACK is a Perl-like command-line tool similar to grep, but searches faster and is more powerful than grep. Especially when you're a programmer, I highly recommend that you use ACK instead of grep. Refer to Learning Linux Video Tutorials .
The use of
ack is well suited for searching with code, so programmers can make complex queries in the source tree with fewer keystrokes. Some very powerful features of the
Ack's attribute
Ack:
Default search Current working directory
default recursive search subdirectory
Ignore metadata directory, such as. svn,.git,csv directory
Ignoring binary files (such as pdf,image,coredumps) and backup files (such as FOO~,*.SWP)
Print line numbers in search results to help find target code
to search for specific file types (such as Perl,c++,makefile). The file type can have multiple file suffixes
Highlight search results
Support Perl's advanced regular expressions, which are more expressive than the GNU regular expressions used by grep.
The ACK is generally faster than grep, compared to the search speed. The speed of the ACK is as long as it behaves in its built-in file type filter. During the search process, ACK maintains a list of recognized file types while skipping unknown or unnecessary file types. It also avoids checking for redundant metadata directories.
Install ACK on Linux
Although the ACK is a standard package in most Linux distributions, it can be easily obtained (for example, in a Debian-based system, it is a ACK-GREP packet, and an ACK packet in a redhat-based system). However, the ACK version bundled with the release is still 1.x, and ack2.0 has been released with more features.
So I'm going to download it on the official website and then install the ACK.
Conveniently, ACK is available as a separate Perl script in the official website, which incorporates all the modules that need to be relied upon. Therefore, you do not need to install additional Perl modules to run this script.
To install the ACK on your Linux system, go to the official website to download the latest version of the ACK. At the time of writing this article, the most recent version is 2.12
$ wget Http://beyondgrep.com/ack-2.12-single-file
$ sudo mv Ack-2.12-single-file/usr/local/bin/ack
$ sudo chmod 0755/usr/local/bin/ack
It is important to note that in a Debian-based system, there is a separate package called an ACK (Han code Converter). So if you happen to have that package, then you have to rename the ACK to avoid naming conflicts.
Use cases for ACK
1. Recursively searches the current directory for the word "eat", and does not match a string similar to "feature" or "eating":
$ ack-w Eat
2. Search for strings with special characters ' $path =. ', all metacharacters (e.g. ' $ ', '. ') Need to be literally matched:
$ Ack-q ' $path =. '/etc
3. In addition to the Dowloads directory, search for "about" words in all directories:
$ ack About--ignore-dir=downloads
4. Search only for PHP files that contain ' protected ' words, then combine the search results by file name to print the search results for each file:
$ ack--php--group protected
5. Get the file name of the makefile that contains the ' cflag ' keyword. The file name *.mk,makefile,makefile,gnumakefile is within the scope of the consideration:
$ ack--make-l Cflag
6. The string to highlight when displaying the entire log file:
$ tail-f/var/log/syslog | Ack--passthru 192.168.1.10
7. To exchange the type of file filtering supported by ACK, run:
$ ack--help-type
For more relevant knowledge, please go to e-Mentor Network for study consultation.
How to improve the search efficiency of text on Linux