mirror of
https://github.com/jbranchaud/til
synced 2026-01-03 23:28:02 +00:00
Add Ignore A Directory During ripgrep Search as a Unix TIL
This commit is contained in:
25
unix/ignore-a-directory-during-ripgrep-search.md
Normal file
25
unix/ignore-a-directory-during-ripgrep-search.md
Normal file
@@ -0,0 +1,25 @@
|
||||
# Ignore A Directory During ripgrep Search
|
||||
|
||||
When searching for patterns in project with many directories and files using
|
||||
`ripgrep`, it is easy to end up with an overwhelming amount of results. If you
|
||||
know that a certain directory of results isn't of interest, you can exclude
|
||||
that directory. This is done with the glob flag (`-g`) and the inverse (`!`)
|
||||
operator.
|
||||
|
||||
Here is an example of just using the `-g` flag. This will find all matches of
|
||||
the pattern within that directory.
|
||||
|
||||
```bash
|
||||
$ rg 'some pattern' -g 'dir/'
|
||||
```
|
||||
|
||||
To instead exclude that directory and by extension search everywhere else, we
|
||||
can invert the glob match with `!`.
|
||||
|
||||
```bash
|
||||
$ rg 'some pattern' -g '!dir/'
|
||||
```
|
||||
|
||||
This says, find the pattern anywhere that is not in `dir/`.
|
||||
|
||||
[source](https://blog.wxm.be/2020/11/08/ignore-folder-in-ripgrep.html)
|
||||
Reference in New Issue
Block a user