Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

The ripgrep Command Is a Better Alternative to the find Command

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

rga (ripgrep-all) is a line-oriented search tool that allows you to look for a regex in a multitude of file types. rga wraps the awesome ripgrep and enables it to search in pdf, docx, sqlite, jpg, movie subtitles (mkv, mp4), etc.

Notice that rga offers a built-in command rga-fzf which integrates fzf.

Installation on Debian/Ubuntu Based Linux Distributions

wajig install ripgrep 

Installation on macOS

brew install ripgrep 

List Files

There are 2 ways to list files using ripgrep. The first way is file name (globbing pattern) based and the second way is file content (regex pattern) based.

List Files with Naming Matching Globbing Pattern

# List all files which would have been searched by `ripgrep`
!rg --files ../
../query-hardware-information-in-linux/query-hardware-information-in-linux.md
../debugging-and-testing-tools-for-windows/debugging-and-testing-tools-for-windows.md
../incognito-mode-for-browsers/incognito-mode-for-browsers.md
../bat-is-a-better-alternative-to-cat/bat-is-a-better-alternative-to-cat.ipynb
../tips-on-windows-terminal/tips-on-windows-terminal.md
../tips-on-public-speech/tips-on-public-speech.md
../tips-on-mumu-app-player/tips-on-mumu-app-player.md
../ripgrep-is-a-better-alternative-to-find/ripgrep-is-a-better-alternative-to-find.ipynb
../tools-with-dark-power/tools-with-dark-power.md
../rip-is-rm-improved/rip-is-rm-improved.ipynb
../format-a-flash-drive-in-a-linux-virtual-machine/format-a-flash-drive-in-a-linux-virtual-machine.md
# List files *.md
!rg --files -g '*.md' ../
../query-hardware-information-in-linux/query-hardware-information-in-linux.md
../debugging-and-testing-tools-for-windows/debugging-and-testing-tools-for-windows.md
../incognito-mode-for-browsers/incognito-mode-for-browsers.md
../tips-on-windows-terminal/tips-on-windows-terminal.md
../tips-on-public-speech/tips-on-public-speech.md
../tips-on-mumu-app-player/tips-on-mumu-app-player.md
../tools-with-dark-power/tools-with-dark-power.md
../format-a-flash-drive-in-a-linux-virtual-machine/format-a-flash-drive-in-a-linux-virtual-machine.md

Notice that single quotes are needed to prevent shell from expanding *.md to files names so that the globbing pattern is passed to ripgrep to match recursively in the specified directory. Without single quotes, shell expands *.md to files matching the pattern in the current directory first and then pass those file names as pattern for ripgrep to match. This is probably not watch you want.

List Files with Content Matching Regular Expression Patterns

# List files whose content match the pattern '.'
!rg -l '.*' ../
../query-hardware-information-in-linux/query-hardware-information-in-linux.md
../debugging-and-testing-tools-for-windows/debugging-and-testing-tools-for-windows.md
../incognito-mode-for-browsers/incognito-mode-for-browsers.md
../bat-is-a-better-alternative-to-cat/bat-is-a-better-alternative-to-cat.ipynb
../tips-on-windows-terminal/tips-on-windows-terminal.md
../tips-on-public-speech/tips-on-public-speech.md
../tips-on-mumu-app-player/tips-on-mumu-app-player.md
../ripgrep-is-a-better-alternative-to-find/ripgrep-is-a-better-alternative-to-find.ipynb
../tools-with-dark-power/tools-with-dark-power.md
../rip-is-rm-improved/rip-is-rm-improved.ipynb
../format-a-flash-drive-in-a-linux-virtual-machine/format-a-flash-drive-in-a-linux-virtual-machine.md

Notice that rg -l '.*' ../ is not the same as rg --files. rg --files list all files which would have been search by ripgrep while rg -l '.*' ../ does not search binary files and empty files. Binary files can be included as well using rg --binary -l '.*' ../, however, empty files are still not listed.

# List text files whose content contains ripgrep
!rg -l ripgrep ../
../ripgrep-is-a-better-alternative-to-find/ripgrep-is-a-better-alternative-to-find.ipynb

Recursively search the current directory for the pattern ripgrep in file content.

Search File Content

Recursively search for files containing the pattern ripgrep under the current directory.

rg ripgrep
ripgrep-is-a-better-alternative-to-find.ipynb
10:    "- Title: The ripgrep Command Is a Better Alternative to the find Command\n",
11:    "- Slug: ripgrep-is-a-better-alternative-to-find\n",
13:    "- Tags: Computer Science, programming, command, command-line, find, ripgrep, Rust, rg\n"
30:    "    wajig install ripgrep \n",
34:    "    brew install ripgrep \n"
54:      "\u001b[0m\u001b[35mripgrep-is-a-better-alternative-to-find.ipynb\u001b[0m\n",
55:      "\u001b[0m\u001b[32m10\u001b[0m:    \"- Title: The \u001b[0m\u001b[1m\u001b[31mripgrep\u001b[0m Command Is a Better Alternative to the find Command\\n\",\n",
56:      "\u001b[0m\u001b[32m11\u001b[0m:    \"- Slug: \u001b[0m\u001b[1m\u001b[31mripgrep\u001b[0m-is-a-better-alternative-to-find\\n\",\n",
57:      "\u001b[0m\u001b[32m13\u001b[0m:    \"- Tags: Computer Science, programming, command, command-line, find, \u001b[0m\u001b[1m\u001b[31mripgrep\u001b[0m, Rust, rg\\n\"\n",
58:      "\u001b[0m\u001b[32m30\u001b[0m:    \"    wajig install \u001b[0m\u001b[1m\u001b[31mripgrep\u001b[0m \\n\",\n",
59:      "\u001b[0m\u001b[32m34\u001b[0m:    \"    brew install \u001b[0m\u001b[1m\u001b[31mripgrep\u001b[0m \\n\"\n",
60:      "\u001b[0m\u001b[32m56\u001b[0m:      \"\\u001b[0m\\u001b[35m\u001b[0m\u001b[1m\u001b[31mripgrep\u001b[0m-is-a-better-alternative-to-find.ipynb\\u001b[0m\\n\",\n",
61:      "\u001b[0m\u001b[32m57\u001b[0m:      \"\\u001b[0m\\u001b[32m10\\u001b[0m:    \\\"- Title: The \\u001b[0m\\u001b[1m\\u001b[31m\u001b[0m\u001b[1m\u001b[31mripgrep\u001b[0m\\u001b[0m Command Is a Better Alternative to the find Command\\\\n\\\",\\n\",\n",
62:      "\u001b[0m\u001b[32m58\u001b[0m:      \"\\u001b[0m\\u001b[32m11\\u001b[0m:    \\\"- Slug: \\u001b[0m\\u001b[1m\\u001b[31m\u001b[0m\u001b[1m\u001b[31mripgrep\u001b[0m\\u001b[0m-is-a-better-alternative-to-find\\\\n\\\",\\n\",\n",
63:      "\u001b[0m\u001b[32m59\u001b[0m:      \"\\u001b[0m\\u001b[32m13\\u001b[0m:    \\\"- Tags: Computer Science, programming, command, command-line, find, \\u001b[0m\\u001b[1m\\u001b[31m\u001b[0m\u001b[1m\u001b[31mripgrep\u001b[0m\\u001b[0m, Rust, rg\\\\n\\\"\\n\",\n",
64:      "\u001b[0m\u001b[32m60\u001b[0m:      \"\\u001b[0m\\u001b[32m30\\u001b[0m:    \\\"    wajig install \\u001b[0m\\u001b[1m\\u001b[31m\u001b[0m\u001b[1m\u001b[31mripgrep\u001b[0m\\u001b[0m \\\\n\\\",\\n\",\n",
65:      "\u001b[0m\u001b[32m61\u001b[0m:      \"\\u001b[0m\\u001b[32m34\\u001b[0m:    \\\"    brew install \\u001b[0m\\u001b[1m\\u001b[31m\u001b[0m\u001b[1m\u001b[31mripgrep\u001b[0m\\u001b[0m \\\\n\\\"\\n\",\n",
66:      "\u001b[0m\u001b[32m62\u001b[0m:      \"\\u001b[0m\\u001b[32m53\\u001b[0m:    \\\"rg \\u001b[0m\\u001b[1m\\u001b[31m\u001b[0m\u001b[1m\u001b[31mripgrep\u001b[0m\\u001b[0m\\\"\\n\",\n",
67:      "\u001b[0m\u001b[32m63\u001b[0m:      \"\\u001b[0m\\u001b[32m63\\u001b[0m:    \\\"- [\\u001b[0m\\u001b[1m\\u001b[31m\u001b[0m\u001b[1m\u001b[31mripgrep\u001b[0m\\u001b[0m @ GitHub](https://github.com/BurntSushi/\\u001b[0m\\u001b[1m\\u001b[31m\u001b[0m\u001b[1m\u001b[31mripgrep\u001b[0m\\u001b[0m)\\\"\\n\"\n",
68:      "\u001b[0m\u001b[32m68\u001b[0m:    \"rg \u001b[0m\u001b[1m\u001b[31mripgrep\u001b[0m\"\n",
69:      "\u001b[0m\u001b[32m85\u001b[0m:    \"rg \u001b[0m\u001b[1m\u001b[31mripgrep\u001b[0m *.markd\"\n",
70:      "\u001b[0m\u001b[32m95\u001b[0m:    \"- [\u001b[0m\u001b[1m\u001b[31mripgrep\u001b[0m @ GitHub](https://github.com/BurntSushi/\u001b[0m\u001b[1m\u001b[31mripgrep\u001b[0m)\"\n"
75:    "rg ripgrep"
87:      "\u001b[0m\u001b[32m10\u001b[0m:    \"- Title: The \u001b[0m\u001b[1m\u001b[31mripgrep\u001b[0m Command Is a Better Alternative to the find Command\\n\",\n",
88:      "\u001b[0m\u001b[32m11\u001b[0m:    \"- Slug: \u001b[0m\u001b[1m\u001b[31mripgrep\u001b[0m-is-a-better-alternative-to-find\\n\",\n",
89:      "\u001b[0m\u001b[32m13\u001b[0m:    \"- Tags: Computer Science, programming, command, command-line, find, \u001b[0m\u001b[1m\u001b[31mripgrep\u001b[0m, Rust, rg\\n\"\n",
90:      "\u001b[0m\u001b[32m30\u001b[0m:    \"    wajig install \u001b[0m\u001b[1m\u001b[31mripgrep\u001b[0m \\n\",\n",
91:      "\u001b[0m\u001b[32m34\u001b[0m:    \"    brew install \u001b[0m\u001b[1m\u001b[31mripgrep\u001b[0m \\n\"\n",
92:      "\u001b[0m\u001b[32m56\u001b[0m:      \"\\u001b[0m\\u001b[35m\u001b[0m\u001b[1m\u001b[31mripgrep\u001b[0m-is-a-better-alternative-to-find.ipynb\\u001b[0m\\n\",\n",
93:      "\u001b[0m\u001b[32m57\u001b[0m:      \"\\u001b[0m\\u001b[32m10\\u001b[0m:    \\\"- Title: The \\u001b[0m\\u001b[1m\\u001b[31m\u001b[0m\u001b[1m\u001b[31mripgrep\u001b[0m\\u001b[0m Command Is a Better Alternative to the find Command\\\\n\\\",\\n\",\n",
94:      "\u001b[0m\u001b[32m58\u001b[0m:      \"\\u001b[0m\\u001b[32m11\\u001b[0m:    \\\"- Slug: \\u001b[0m\\u001b[1m\\u001b[31m\u001b[0m\u001b[1m\u001b[31mripgrep\u001b[0m\\u001b[0m-is-a-better-alternative-to-find\\\\n\\\",\\n\",\n",
95:      "\u001b[0m\u001b[32m59\u001b[0m:      \"\\u001b[0m\\u001b[32m13\\u001b[0m:    \\\"- Tags: Computer Science, programming, command, command-line, find, \\u001b[0m\\u001b[1m\\u001b[31m\u001b[0m\u001b[1m\u001b[31mripgrep\u001b[0m\\u001b[0m, Rust, rg\\\\n\\\"\\n\",\n",
96:      "\u001b[0m\u001b[32m60\u001b[0m:      \"\\u001b[0m\\u001b[32m30\\u001b[0m:    \\\"    wajig install \\u001b[0m\\u001b[1m\\u001b[31m\u001b[0m\u001b[1m\u001b[31mripgrep\u001b[0m\\u001b[0m \\\\n\\\",\\n\",\n",
97:      "\u001b[0m\u001b[32m61\u001b[0m:      \"\\u001b[0m\\u001b[32m34\\u001b[0m:    \\\"    brew install \\u001b[0m\\u001b[1m\\u001b[31m\u001b[0m\u001b[1m\u001b[31mripgrep\u001b[0m\\u001b[0m \\\\n\\\"\\n\",\n",
98:      "\u001b[0m\u001b[32m62\u001b[0m:      \"\\u001b[0m\\u001b[32m56\\u001b[0m:      \\\"\\\\u001b[0m\\\\u001b[35m\\u001b[0m\\u001b[1m\\u001b[31m\u001b[0m\u001b[1m\u001b[31mripgrep\u001b[0m\\u001b[0m-is-a-better-alternative-to-find.ipynb\\\\u001b[0m\\\\n\\\",\\n\",\n",
99:      "\u001b[0m\u001b[32m63\u001b[0m:      \"\\u001b[0m\\u001b[32m57\\u001b[0m:      \\\"\\\\u001b[0m\\\\u001b[32m10\\\\u001b[0m:    \\\\\\\"- Title: The \\\\u001b[0m\\\\u001b[1m\\\\u001b[31m\\u001b[0m\\u001b[1m\\u001b[31m\u001b[0m\u001b[1m\u001b[31mripgrep\u001b[0m\\u001b[0m\\\\u001b[0m Command Is a Better Alternative to the find Command\\\\\\\\n\\\\\\\",\\\\n\\\",\\n\",\n",
100:      "\u001b[0m\u001b[32m64\u001b[0m:      \"\\u001b[0m\\u001b[32m58\\u001b[0m:      \\\"\\\\u001b[0m\\\\u001b[32m11\\\\u001b[0m:    \\\\\\\"- Slug: \\\\u001b[0m\\\\u001b[1m\\\\u001b[31m\\u001b[0m\\u001b[1m\\u001b[31m\u001b[0m\u001b[1m\u001b[31mripgrep\u001b[0m\\u001b[0m\\\\u001b[0m-is-a-better-alternative-to-find\\\\\\\\n\\\\\\\",\\\\n\\\",\\n\",\n",
101:      "\u001b[0m\u001b[32m65\u001b[0m:      \"\\u001b[0m\\u001b[32m59\\u001b[0m:      \\\"\\\\u001b[0m\\\\u001b[32m13\\\\u001b[0m:    \\\\\\\"- Tags: Computer Science, programming, command, command-line, find, \\\\u001b[0m\\\\u001b[1m\\\\u001b[31m\\u001b[0m\\u001b[1m\\u001b[31m\u001b[0m\u001b[1m\u001b[31mripgrep\u001b[0m\\u001b[0m\\\\u001b[0m, Rust, rg\\\\\\\\n\\\\\\\"\\\\n\\\",\\n\",\n",
102:      "\u001b[0m\u001b[32m66\u001b[0m:      \"\\u001b[0m\\u001b[32m60\\u001b[0m:      \\\"\\\\u001b[0m\\\\u001b[32m30\\\\u001b[0m:    \\\\\\\"    wajig install \\\\u001b[0m\\\\u001b[1m\\\\u001b[31m\\u001b[0m\\u001b[1m\\u001b[31m\u001b[0m\u001b[1m\u001b[31mripgrep\u001b[0m\\u001b[0m\\\\u001b[0m \\\\\\\\n\\\\\\\",\\\\n\\\",\\n\",\n",
103:      "\u001b[0m\u001b[32m67\u001b[0m:      \"\\u001b[0m\\u001b[32m61\\u001b[0m:      \\\"\\\\u001b[0m\\\\u001b[32m34\\\\u001b[0m:    \\\\\\\"    brew install \\\\u001b[0m\\\\u001b[1m\\\\u001b[31m\\u001b[0m\\u001b[1m\\u001b[31m\u001b[0m\u001b[1m\u001b[31mripgrep\u001b[0m\\u001b[0m\\\\u001b[0m \\\\\\\\n\\\\\\\"\\\\n\\\",\\n\",\n",
104:      "\u001b[0m\u001b[32m68\u001b[0m:      \"\\u001b[0m\\u001b[32m62\\u001b[0m:      \\\"\\\\u001b[0m\\\\u001b[32m53\\\\u001b[0m:    \\\\\\\"rg \\\\u001b[0m\\\\u001b[1m\\\\u001b[31m\\u001b[0m\\u001b[1m\\u001b[31m\u001b[0m\u001b[1m\u001b[31mripgrep\u001b[0m\\u001b[0m\\\\u001b[0m\\\\\\\"\\\\n\\\",\\n\",\n",
105:      "\u001b[0m\u001b[32m69\u001b[0m:      \"\\u001b[0m\\u001b[32m63\\u001b[0m:      \\\"\\\\u001b[0m\\\\u001b[32m63\\\\u001b[0m:    \\\\\\\"- [\\\\u001b[0m\\\\u001b[1m\\\\u001b[31m\\u001b[0m\\u001b[1m\\u001b[31m\u001b[0m\u001b[1m\u001b[31mripgrep\u001b[0m\\u001b[0m\\\\u001b[0m @ GitHub](https://github.com/BurntSushi/\\\\u001b[0m\\\\u001b[1m\\\\u001b[31m\\u001b[0m\\u001b[1m\\u001b[31m\u001b[0m\u001b[1m\u001b[31mripgrep\u001b[0m\\u001b[0m\\\\u001b[0m)\\\\\\\"\\\\n\\\"\\n\",\n",
106:      "\u001b[0m\u001b[32m70\u001b[0m:      \"\\u001b[0m\\u001b[32m68\\u001b[0m:    \\\"rg \\u001b[0m\\u001b[1m\\u001b[31m\u001b[0m\u001b[1m\u001b[31mripgrep\u001b[0m\\u001b[0m\\\"\\n\",\n",
107:      "\u001b[0m\u001b[32m71\u001b[0m:      \"\\u001b[0m\\u001b[32m85\\u001b[0m:    \\\"rg \\u001b[0m\\u001b[1m\\u001b[31m\u001b[0m\u001b[1m\u001b[31mripgrep\u001b[0m\\u001b[0m *.markd\\\"\\n\",\n",
108:      "\u001b[0m\u001b[32m72\u001b[0m:      \"\\u001b[0m\\u001b[32m95\\u001b[0m:    \\\"- [\\u001b[0m\\u001b[1m\\u001b[31m\u001b[0m\u001b[1m\u001b[31mripgrep\u001b[0m\\u001b[0m @ GitHub](https://github.com/BurntSushi/\\u001b[0m\\u001b[1m\\u001b[31m\u001b[0m\u001b[1m\u001b[31mripgrep\u001b[0m\\u001b[0m)\\\"\\n\"\n",
109:      "\u001b[0m\u001b[32m77\u001b[0m:    \"rg \u001b[0m\u001b[1m\u001b[31mripgrep\u001b[0m\"\n",
110:      "\u001b[0m\u001b[32m94\u001b[0m:    \"rg \u001b[0m\u001b[1m\u001b[31mripgrep\u001b[0m *.markd\"\n",
111:      "\u001b[0m\u001b[32m104\u001b[0m:    \"- [\u001b[0m\u001b[1m\u001b[31mripgrep\u001b[0m @ GitHub](https://github.com/BurntSushi/\u001b[0m\u001b[1m\u001b[31mripgrep\u001b[0m)\"\n"
116:    "rg ripgrep *.ipynb"
126:    "- [ripgrep @ GitHub](https://github.com/BurntSushi/ripgrep)"

Recursively search for vim in files with the globbing pattern Dockerfile under the currently directory.

!rg vim -g Dockerfile

Recursively search for docker in all files except the directory .venv/.

!rg -uuu docker -g '!.venv/'

Recursively search for the pattern ripgrep in files with glob patterns *.ipynb or *.markdown under the directory ../../...

!rg ripgrep -g '*.ipynb' -g '*.markdown' ../../..