The Silver Searcher: the alternative tool for internal searches, faster than grep on Linux

by time news

2023-05-19 08:15:00

Silver Searcher is a free and open source cross-platform source code search tool similar to ack (a tool similar to grep, [ 2 ] for programmers) but faster. It runs on Unix-like systems and Windows operating systems.

The main difference between “The Silver Searcher” the silver finder y the ack is that the former is designed for speed, and benchmark tests show that it is, in fact, faster.

If you spend a lot of time reading and searching your code, then you need this tool. Your goal is to be quick and ignore files you don’t want to be searched for. In this guide, we will show how to install and use The Silver Searcher in Linux .

How to install and use The Silver Searcher on Linux

The package Silver Searcher It is available on most Linux distributions, you can easily install it via your package manager as shown.

$ sudo apt install silversearcher-ag			#Debian/Ubuntu 
$ sudo yum install epel-release the_silver_searcher	#RHEL/CentOS
$ sudo dnf install silversearcher-ag			#Fedora 22+
$ sudo zypper install the_silver_searcher		#openSUSE
$ sudo pacman -S the_silver_searcher           		#Arch 

After installing it, you can run the command line tool ag with the following syntax.

$ ag [opciones de tipo de archivo] [PATRÓN] /ruta/al/archivo

To see a list of all supported file types, use the following command.

$ ag --list-file-types

This example shows how to search recursively all scripts containing the word “root” In the address book ~/bin/ .

$ ag root ./bin/

Find a pattern in files

For print los matching file names con the boss and the number of matches in each file, apart from the number of matching lines, use the switch -c as shown.

$ ag -c root ./bin/

print number of matches

To match case, add the flag -s as shown.

$ ag -cs ROOT ./bin/
$ ag -cs root ./bin/

Regardless of whether they are case-sensitive, use the -i option

To print statistics for a search operation, such as files scanned, time spent, etc., use the option --stats.

$ ag -i -c foo --stats ./bin/

Print Lookup Summary

Flag -w tells her to ag that only matches whole words similar to the grep command.

$ ag -w root ./bin/

You can display the column numbers in the results using the --columnoption.

$ ag --column foo ./bin/

Show column numbers in output

You can also use ag to search through purely text files, using the -tswitch and the -aswitch is used to search for all kinds of files. Also, the -uswitch allows you to search all files, including hidden files.

$ ag -t root /etc/
O
$ ag -a root /etc/
O
$ ag -u root /etc/

Ag also supports searching through the contents of compressed files, using the -z bandera.

$ ag -z abuscar ficherocomprimido.gz

Find content in compressed files

You can also enable symlink tracking (symlinks in summary) with the -fbandera.

$ ag -tf root /etc/ 

By default, ag search in 25 depth directories, you can set the depth of the search using the --depthswitch, for example.

$ ag --profundidad 40 -tf root /etc/

There are more interesting options with “ag”, such as limiting the output to X number of lines below the name with the “-m” option

For more information, see the Silver Seeker man page for a full list of usage options.

$ man ag

To find out how the silver finder works, check out their Github repository: .

That’s all! Silver Searcher is a quick and useful tool for finding files that make sense to search. It is intended for programmers and administrators to quickly search through a large base of source code or information. You can give it a try and share your thoughts with us via the feedback form below.

Pin It

#Silver #Searcher #alternative #tool #internal #searches #faster #grep #Linux

You may also like

Leave a Comment