If I have my folder like this:
dir:
├── 1.index1.html
├── 2.index2.html
├── 3.index3.html
├── a
│ ├── 1.index1.html
│
How can I tell ripgrep in the command to exclude only the file index1.html in the root folder, but still searching the index1.html in folder a?
ripgrep has support for this, regardless of the globbing syntax that is support by your shell because its support is independent of the shell.
ripgrep's
-g/--globflag allows you to include or exclude files. And in particular, it follows the same semantics that gitignore uses (seeman gitignore). This means that if you start a glob pattern with a/, then it will only match that specific path relative to where ripgrep is running. For example:When using the
-gflag, the!means to ignore files matching that pattern. When we runrg --files -g '!index1.html', it will result in ignoring all files namedindex1.html. But if we use!/index1.html, then it will only ignore the top-levelindex1.html. Similarly, if we use!/a/index1.html, then it would only ignore that file:ripgrep has more details about the
-g/--globflag in its guide.