Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ggreer/the_silver_searcher
A code-searching tool similar to ack, but faster.
https://github.com/ggreer/the_silver_searcher
ag c command-line-tool pcre search-in-text silver-searcher
Last synced: 6 days ago
JSON representation
A code-searching tool similar to ack, but faster.
- Host: GitHub
- URL: https://github.com/ggreer/the_silver_searcher
- Owner: ggreer
- License: apache-2.0
- Created: 2011-11-19T19:50:47.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2023-12-26T04:01:03.000Z (10 months ago)
- Last Synced: 2024-04-15T14:19:25.825Z (7 months ago)
- Topics: ag, c, command-line-tool, pcre, search-in-text, silver-searcher
- Language: C
- Homepage: http://geoff.greer.fm/ag/
- Size: 2.31 MB
- Stars: 25,691
- Watchers: 428
- Forks: 1,382
- Open Issues: 552
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
- awesome-github - 文件内容搜索-ag
- awesome-thesis - silversearcher-ag - ditch your grep, silversearcher is a blazing fast code searching tool (Tools / Writing)
- awesome - the_silver_searcher
- awesome-shell - ag - Super fast string search through a directory hierarchy (Command-Line Productivity)
- awesome-ccamel - ggreer/the_silver_searcher - A code-searching tool similar to ack, but faster. (C)
- fucking-Awesome-Linux-Software - ![Open-Source Software - A code-searching tool similar to ack, but faster. (Command Line Utilities / Tools)
- awesome-starred-test - ggreer/the_silver_searcher - A code-searching tool similar to ack, but faster. (C)
- my-awesome-github-stars - ggreer/the_silver_searcher - A code-searching tool similar to ack, but faster. (C)
- awesome-starred - the_silver_searcher - A code-searching tool similar to ack, but faster. (C)
- awesome-starred - ggreer/the_silver_searcher - A code-searching tool similar to ack, but faster. (c)
- awesome-robotic-tooling - ag - A code-searching tool similar to ack, but faster. (Interaction / Command Line)
- jimsghstars - ggreer/the_silver_searcher - A code-searching tool similar to ack, but faster. (C)
- awesome-robotic-tooling - ag - A code-searching tool similar to ack, but faster. (User Interaction / Command Line Interface)
- awesome-list - The Silver Searcher - A code-searching tool similar to ack, but faster. (Containers & Language Extentions & Linting / For JavaScript)
- Awesome-Linux-Software - ![Open-Source Software - A code-searching tool similar to ack, but faster. (Command Line Utilities / Tools)
- starred-awesome - the_silver_searcher - A code-searching tool similar to ack, but faster. (C)
- StarryDivineSky - ggreer/the_silver_searcher
- awesome-for-oneliner - the_silver_searcher - A code searching tool similar to ack, with a focus on speed. (The name of command: `ag`) (Grep Replacement / Open USP Tsukubai)
- xiao-awesome - the_silver_searcher
README
# The Silver Searcher
A code searching tool similar to `ack`, with a focus on speed.
[![Build Status](https://travis-ci.org/ggreer/the_silver_searcher.svg?branch=master)](https://travis-ci.org/ggreer/the_silver_searcher)
[![Floobits Status](https://floobits.com/ggreer/ag.svg)](https://floobits.com/ggreer/ag/redirect)
[![#ag on Freenode](https://img.shields.io/badge/Freenode-%23ag-brightgreen.svg)](https://webchat.freenode.net/?channels=ag)
Do you know C? Want to improve ag? [I invite you to pair with me](http://geoff.greer.fm/2014/10/13/help-me-get-to-ag-10/).
## What's so great about Ag?
* It is an order of magnitude faster than `ack`.
* It ignores file patterns from your `.gitignore` and `.hgignore`.
* If there are files in your source repo you don't want to search, just add their patterns to a `.ignore` file. (\*cough\* `*.min.js` \*cough\*)
* The command name is 33% shorter than `ack`, and all keys are on the home row!Ag is quite stable now. Most changes are new features, minor bug fixes, or performance improvements. It's much faster than Ack in my benchmarks:
ack test_blah ~/code/ 104.66s user 4.82s system 99% cpu 1:50.03 total
ag test_blah ~/code/ 4.67s user 4.58s system 286% cpu 3.227 total
Ack and Ag found the same results, but Ag was 34x faster (3.2 seconds vs 110 seconds). My `~/code` directory is about 8GB. Thanks to git/hg/ignore, Ag only searched 700MB of that.
There are also [graphs of performance across releases](http://geoff.greer.fm/ag/speed/).
## How is it so fast?
* Ag uses [Pthreads](https://en.wikipedia.org/wiki/POSIX_Threads) to take advantage of multiple CPU cores and search files in parallel.
* Files are `mmap()`ed instead of read into a buffer.
* Literal string searching uses [Boyer-Moore strstr](https://en.wikipedia.org/wiki/Boyer%E2%80%93Moore_string_search_algorithm).
* Regex searching uses [PCRE's JIT compiler](http://sljit.sourceforge.net/pcre.html) (if Ag is built with PCRE >=8.21).
* Ag calls `pcre_study()` before executing the same regex on every file.
* Instead of calling `fnmatch()` on every pattern in your ignore files, non-regex patterns are loaded into arrays and binary searched.I've written several blog posts showing how I've improved performance. These include how I [added pthreads](http://geoff.greer.fm/2012/09/07/the-silver-searcher-adding-pthreads/), [wrote my own `scandir()`](http://geoff.greer.fm/2012/09/03/profiling-ag-writing-my-own-scandir/), [benchmarked every revision to find performance regressions](http://geoff.greer.fm/2012/08/25/the-silver-searcher-benchmarking-revisions/), and profiled with [gprof](http://geoff.greer.fm/2012/02/08/profiling-with-gprof/) and [Valgrind](http://geoff.greer.fm/2012/01/23/making-programs-faster-profiling/).
## Installing
### macOS
brew install the_silver_searcher
or
port install the_silver_searcher
### Linux
* Ubuntu >= 13.10 (Saucy) or Debian >= 8 (Jessie)
apt-get install silversearcher-ag
* Fedora 21 and loweryum install the_silver_searcher
* Fedora 22+dnf install the_silver_searcher
* RHEL7+yum install epel-release.noarch the_silver_searcher
* Gentooemerge -a sys-apps/the_silver_searcher
* Archpacman -S the_silver_searcher
* Slackware
sbopkg -i the_silver_searcher
* openSUSE
zypper install the_silver_searcher
* CentOS
yum install the_silver_searcher
* NixOS/Nix/Nixpkgs
nix-env -iA silver-searcher
* SUSE Linux Enterprise: Follow [these simple instructions](https://software.opensuse.org/download.html?project=utilities&package=the_silver_searcher).
### BSD
* FreeBSD
pkg install the_silver_searcher
* OpenBSD/NetBSDpkg_add the_silver_searcher
### Windows
* Win32/64
Unofficial daily builds are [available](https://github.com/k-takata/the_silver_searcher-win32).
* wingetwinget install "The Silver Searcher"
Notes:
- This installs a [release](https://github.com/JFLarvoire/the_silver_searcher/releases) of ag.exe optimized for Windows.
- winget is intended to become the default package manager client for Windows.
As of June 2020, it's still in beta, and can be installed using instructions [there](https://github.com/microsoft/winget-cli).
- The setup script in the Ag's winget package installs ag.exe in the first directory that matches one of these criteria:
1. Over a previous instance of ag.exe *from the same [origin](https://github.com/JFLarvoire/the_silver_searcher)* found in the PATH
2. In the directory defined in environment variable bindir_%PROCESSOR_ARCHITECTURE%
3. In the directory defined in environment variable bindir
4. In the directory defined in environment variable windir
* Chocolateychoco install ag
* MSYS2pacman -S mingw-w64-{i686,x86_64}-ag
* CygwinRun the relevant [`setup-*.exe`](https://cygwin.com/install.html), and select "the\_silver\_searcher" in the "Utils" category.
## Building from source
### Building master
1. Install dependencies (Automake, pkg-config, PCRE, LZMA):
* macOS:brew install automake pkg-config pcre xz
orport install automake pkgconfig pcre xz
* Ubuntu/Debian:apt-get install -y automake pkg-config libpcre3-dev zlib1g-dev liblzma-dev
* Fedora:yum -y install pkgconfig automake gcc zlib-devel pcre-devel xz-devel
* CentOS:yum -y groupinstall "Development Tools"
yum -y install pcre-devel xz-devel zlib-devel
* openSUSE:zypper source-install --build-deps-only the_silver_searcher
* Windows: It's complicated. See [this wiki page](https://github.com/ggreer/the_silver_searcher/wiki/Windows).
2. Run the build script (which just runs aclocal, automake, etc):./build.sh
On Windows (inside an msys/MinGW shell):
make -f Makefile.w32
3. Make install:sudo make install
### Building a release tarball
GPG-signed releases are available [here](http://geoff.greer.fm/ag).
Building release tarballs requires the same dependencies, except for automake and pkg-config. Once you've installed the dependencies, just run:
./configure
make
make installYou may need to use `sudo` or run as root for the make install.
## Editor Integration
### Vim
You can use Ag with [ack.vim](https://github.com/mileszs/ack.vim) by adding the following line to your `.vimrc`:
let g:ackprg = 'ag --nogroup --nocolor --column'
or:
let g:ackprg = 'ag --vimgrep'
Which has the same effect but will report every match on the line.
### Emacs
You can use [ag.el][] as an Emacs front-end to Ag. See also: [helm-ag].
[ag.el]: https://github.com/Wilfred/ag.el
[helm-ag]: https://github.com/syohex/emacs-helm-ag### TextMate
TextMate users can use Ag with [my fork](https://github.com/ggreer/AckMate) of the popular AckMate plugin, which lets you use both Ack and Ag for searching. If you already have AckMate you just want to replace Ack with Ag, move or delete `"~/Library/Application Support/TextMate/PlugIns/AckMate.tmplugin/Contents/Resources/ackmate_ack"` and run `ln -s /usr/local/bin/ag "~/Library/Application Support/TextMate/PlugIns/AckMate.tmplugin/Contents/Resources/ackmate_ack"`
## Other stuff you might like
* [Ack](https://github.com/petdance/ack3) - Better than grep. Without Ack, Ag would not exist.
* [ack.vim](https://github.com/mileszs/ack.vim)
* [Exuberant Ctags](http://ctags.sourceforge.net/) - Faster than Ag, but it builds an index beforehand. Good for *really* big codebases.
* [Git-grep](http://git-scm.com/docs/git-grep) - As fast as Ag but only works on git repos.
* [fzf](https://github.com/junegunn/fzf) - A command-line fuzzy finder
* [ripgrep](https://github.com/BurntSushi/ripgrep)
* [Sack](https://github.com/sampson-chen/sack) - A utility that wraps Ack and Ag. It removes a lot of repetition from searching and opening matching files.