How to improve the efficiency of text search in CentOS system?

Source: Internet
Author: User
Tags ack php file centos perl script

How to improve the efficiency of text search in CentOS system?

For system administrators or programmers, grep-type tools are probably the most popular when you need to search for specific text or patterns in a complex configuration directory or in a large source tree.

If grep is one of your favorite tools, you might prefer an ACK. An ACK is a Perl based command-line tool, but searches faster and has more power than grep. Especially when you're a programmer, I highly recommend you use an ACK instead of grep.

The use of ACK is well suited to code search, so programmers can make complex queries in the source tree, requiring fewer keystrokes.

The characteristics of an ACK

Some very powerful features of ACK:

Default search Current working directory

Default Recursive Search subdirectories

Ignore metadata directories, such as. Svn,.git,csv Directory

Ignore binaries (such as pdf,image,coredumps) and backup files (such as FOO~,*.SWP)

Print line numbers in search results to help find the target code

Can search for specific file types (such as Perl,c++,makefile), which can have multiple file suffixes

Highlight search Results

Advanced Regular expressions that support Perl 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 an ACK is as long as it is shown in the built-in file type filter. During the search process, the ACK maintains a list of approved file types while skipping unknown or unnecessary file types. It also avoids checking for redundant metadata directories.

To install an ACK on Linux

Although the ACK is a standard package in most Linux distributions, it is easy to obtain (for example, in a Debian based system, an ACK package on a redhat system), but the ACK version bundled with the release is still 1.x, Ack-grep. And ack2.0 has been released, and has more features.

So I'm going to download it on the official website and then install the ACK.

Conveniently, the ACK is available in the official website of cocoa as a separate Perl script, which incorporates all the modules that need to be relied upon. Therefore, you do not need to install a Perl module to run this script.

To install an ACK in your Linux system, go to the official website to download the latest version of the ACK. When writing this article, the latest 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 should be noted that in a Debian based system, there is a separate packet called ACK (Chinese code Converter). So if you happen to have that package, then you have to rename the ACK to avoid naming conflicts.

Use Case for ACK

1. Recursively search the word "eat" in the current directory and do not match a string similar to "feature" or "eating":

$ ack-w Eat

2. Search for strings with special characters ' $path =. ', all metacharacters (such as ' $ ', '. ') Need to be literally matched:

$ Ack-q ' $path =. '/etc

3. In addition to the Dowloads directory, search all directories for "about" words:

$ ack About--ignore-dir=downloads

4. Search only the PHP file containing the word ' protected ', and then combine the search results by file name to print the corresponding search results for each file:

$ ack--php--group protected

5. Gets the file name of the makefile containing the ' cflag ' keyword. The file name *.mk,makefile,makefile,gnumakefile is in the scope of 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. For the ACK-supported file filter type, run:

$ ack--help-type

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.