{"id":11202,"date":"2019-03-11T06:24:08","date_gmt":"2019-03-11T06:24:08","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=11202"},"modified":"2019-03-11T06:24:08","modified_gmt":"2019-03-11T06:24:08","slug":"the-silver-searcher-a-code-searching-tool-for-programmers-2","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/11\/the-silver-searcher-a-code-searching-tool-for-programmers-2\/","title":{"rendered":"The Silver Searcher \u2013 A Code Searching Tool for Programmers"},"content":{"rendered":"<p><strong>The Silver Searcher<\/strong>\u00a0is a free and open source, cross platform source code searching tool similar to\u00a0<strong>ack<\/strong>\u00a0(a\u00a0<a href=\"https:\/\/www.tecmint.com\/12-practical-examples-of-linux-grep-command\/\" target=\"_blank\" rel=\"noopener\">grep-like tool<\/a>\u00a0for programmers) but faster. It runs on Unix-like systems and Windows operating systems.<\/p>\n<p>The major difference between the\u00a0<strong>silver searcher<\/strong>\u00a0and\u00a0<strong>ack<\/strong>\u00a0is that the former is designed for speed, and benchmark tests prove that it is indeed faster.<\/p>\n<p>If you spend a lot of time reading and searching through your code, then you need this tool. It aims at being fast and ignoring files that you don\u2019t want to be searched. In this guide, we will show how to install and use\u00a0<strong>The Silver Searcher<\/strong>\u00a0in\u00a0<strong>Linux<\/strong>.<\/p>\n<h3>How to Install and Use The Silver Searcher in Linux<\/h3>\n<p>The\u00a0<strong>silver searcher<\/strong>\u00a0package is available on most Linux distributions, you can easily install it via your package manager as shown.<\/p>\n<pre>$ sudo apt install silversearcher-ag\t\t\t\t\t#Debian\/Ubuntu \r\n$ sudo yum install epel-release the_silver_searcher\t\t        #RHEL\/CentOS\r\n$ sudo dnf install silversearcher-ag\t\t\t\t\t#Fedora 22+\r\n$ sudo zypper install the_silver_searcher\t\t\t\t#openSUSE\r\n$ sudo pacman -S the_silver_searcher           \t\t\t\t#Arch \r\n<\/pre>\n<p><center>After installing it, you can run the\u00a0<strong>ag<\/strong>\u00a0command line tool with the following syntax.<\/center><\/p>\n<pre>$ ag file-type options PATTERN \/path\/to\/file\r\n<\/pre>\n<p>To see a list of all supported file types, use the following command.<\/p>\n<pre>$ ag  --list-file-types\r\n<\/pre>\n<p>This example shows how to recursively search for all scripts that contain the word\u00a0<strong>\u201croot\u201d<\/strong>\u00a0under the directory\u00a0<strong>~\/bin\/<\/strong>.<\/p>\n<pre>$ ag root .\/bin\/\r\n<\/pre>\n<div id=\"attachment_30946\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/10\/search-a-pattern-in-files-using-ag.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-30946\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/10\/search-a-pattern-in-files-using-ag.png\" sizes=\"auto, (max-width: 802px) 100vw, 802px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/10\/search-a-pattern-in-files-using-ag.png 802w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/10\/search-a-pattern-in-files-using-ag-768x257.png 768w\" alt=\"Search a Pattern in Files\" width=\"802\" height=\"268\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Search a Pattern in Files<\/p>\n<\/div>\n<p>To print the filenames matching\u00a0<strong>PATTERN<\/strong>\u00a0and the number of matches in each file, other than the number of matching lines, use the\u00a0<code>-c<\/code>\u00a0switch as shown.<\/p>\n<pre>$ ag -c root .\/bin\/\r\n<\/pre>\n<div id=\"attachment_30949\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/10\/only-print-number-of-matches-in-each-line.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-30949\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/10\/only-print-number-of-matches-in-each-line.png\" alt=\"Print Number of Matches\" width=\"502\" height=\"173\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Print Number of Matches<\/p>\n<\/div>\n<p>To match case-sensitively, add the\u00a0<code>-s<\/code>\u00a0flag as shown.<\/p>\n<pre>$ ag -cs ROOT .\/bin\/\r\n$ ag -cs root .\/bin\/\r\n<\/pre>\n<div id=\"attachment_30948\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/10\/match-case-senstively.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-30948\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/10\/match-case-senstively.png\" alt=\"Match Case Sensitive\" width=\"582\" height=\"211\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Match Case Sensitive<\/p>\n<\/div>\n<p>To print statistics of of a search operation such as files scanned, time taken, etc., use the the\u00a0<code>--stats<\/code>\u00a0option.<\/p>\n<pre>$ ag -c root --stats .\/bin\/\r\n<\/pre>\n<div id=\"attachment_30947\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/10\/print-search-operation-stats.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-30947\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/10\/print-search-operation-stats.png\" alt=\"Print Search Operations Summary\" width=\"632\" height=\"249\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Print Search Operations Summary<\/p>\n<\/div>\n<p>The\u00a0<code>-w<\/code>\u00a0flag tells\u00a0<strong>ag<\/strong>\u00a0to only match whole words similar to\u00a0<a href=\"https:\/\/www.tecmint.com\/linux-grep-commands-character-classes-bracket-expressions\/\" target=\"_blank\" rel=\"noopener\">grep command<\/a>.<\/p>\n<pre>$ ag -w root .\/bin\/\r\n<\/pre>\n<p>You can show column numbers in results using the\u00a0<code>--column<\/code>\u00a0option.<\/p>\n<pre>$ ag --column root .\/bin\/\r\n<\/pre>\n<div id=\"attachment_30950\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/10\/show-column-numbers-in-output.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-30950\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/10\/show-column-numbers-in-output.png\" alt=\"Show Column Numbers in Output\" width=\"742\" height=\"268\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Show Column Numbers in Output<\/p>\n<\/div>\n<p>You can also use\u00a0<strong>ag<\/strong>\u00a0to search through purely text files, using the\u00a0<code>-t<\/code>\u00a0switch and the\u00a0<code>-a<\/code>\u00a0switch is used to search all types of files. In addition, the\u00a0<code>-u<\/code>\u00a0switch enables searching though all files, including hidden files.<\/p>\n<pre>$ ag -t root \/etc\/\r\nOR\r\n$ ag -a root \/etc\/\r\nOR\r\n$ ag -u root \/etc\/\r\n<\/pre>\n<p><strong>Ag<\/strong>\u00a0also supports searching through the contents of compressed files, using the\u00a0<code>-z<\/code>\u00a0flag.<\/p>\n<pre>$ ag -z root wondershaper.gz\r\n<\/pre>\n<div id=\"attachment_30951\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/10\/search-content-of-compressed-files.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-30951\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/10\/search-content-of-compressed-files.png\" alt=\"Search Content in Compressed Files\" width=\"712\" height=\"173\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Search Content in Compressed Files<\/p>\n<\/div>\n<p>You can also enable following of symbolic links (symlinks in short) with the\u00a0<code>-f<\/code>\u00a0flag.<\/p>\n<pre>$ ag -tf root \/etc\/ \r\n<\/pre>\n<p>By default,\u00a0<strong>ag<\/strong>\u00a0searches\u00a0<strong>25<\/strong>\u00a0directories deep, you can set the depth of the search using the\u00a0<code>--depth<\/code>\u00a0switch, for example.<\/p>\n<pre>$ ag --depth 40 -tf root \/etc\/\r\n<\/pre>\n<p>For more information, see the silver searcher\u2019s man page for a complete list of usage options.<\/p>\n<pre>$ man ag\r\n<\/pre>\n<p>To find out, how the silver searcher works, see its Github repository:\u00a0<a href=\"https:\/\/github.com\/ggreer\/the_silver_searcher\" target=\"_blank\" rel=\"nofollow noopener\">https:\/\/github.com\/ggreer\/the_silver_searcher<\/a>.<\/p>\n<p>That\u2019s it!\u00a0<strong>The Silver Searcher<\/strong>\u00a0is a fast, useful tool for searching through files that make sense to search. It is intended for programmers for quickly searching though large source-code base.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/the-silver-searcher-a-code-searching-tool-for-linux\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Silver Searcher\u00a0is a free and open source, cross platform source code searching tool similar to\u00a0ack\u00a0(a\u00a0grep-like tool\u00a0for programmers) but faster. It runs on Unix-like systems and Windows operating systems. The major difference between the\u00a0silver searcher\u00a0and\u00a0ack\u00a0is that the former is designed for speed, and benchmark tests prove that it is indeed faster. If you spend a &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/11\/the-silver-searcher-a-code-searching-tool-for-programmers-2\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;The Silver Searcher \u2013 A Code Searching Tool for Programmers&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-11202","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/11202","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=11202"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/11202\/revisions"}],"predecessor-version":[{"id":11203,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/11202\/revisions\/11203"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=11202"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=11202"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=11202"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}