diff --git a/README.md b/README.md index 20b2477..d1b10bf 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ pairing with smart people at Hashrocket. For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186). -_1280 TILs and counting..._ +_1281 TILs and counting..._ --- @@ -1250,6 +1250,7 @@ _1280 TILs and counting..._ - [Grep For Files With Multiple Matches](unix/grep-for-files-with-multiple-matches.md) - [Grep For Multiple Patterns](unix/grep-for-multiple-patterns.md) - [Hexdump A Compiled File](unix/hexdump-a-compiled-file.md) +- [Ignore A Directory During ripgrep Search](unix/ignore-a-directory-during-ripgrep-search.md) - [Ignore The Alias When Running A Command](unix/ignore-the-alias-when-running-a-command.md) - [Interactively Browse Available Node Versions](unix/interactively-browse-availabile-node-versions.md) - [Jump To The Ends Of Your Shell History](unix/jump-to-the-ends-of-your-shell-history.md) diff --git a/unix/ignore-a-directory-during-ripgrep-search.md b/unix/ignore-a-directory-during-ripgrep-search.md new file mode 100644 index 0000000..2579de5 --- /dev/null +++ b/unix/ignore-a-directory-during-ripgrep-search.md @@ -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)