1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-03 07:08:01 +00:00

Add Find All Files Matching A Name With fd as a Unix TIL

This commit is contained in:
jbranchaud
2022-10-12 17:18:49 -05:00
parent 9d16f2cf59
commit 99331d0d13
2 changed files with 36 additions and 1 deletions

View File

@@ -0,0 +1,34 @@
# Find All Files Matching A Name With fd
The [`fd` command](https://github.com/sharkdp/fd) can be used to find files in
your file system by name. Though it has some nice defaults—it excludes hidden
directories and respects your `.gitignore` file—you may need to configure
those.
For instance, I want to find ALL _sitemap_ files in a monorepo.
```bash
$ fd -I -H sitemap.xml
```
The `-I` flag tells `fd` to not respect the `.gitignore` file. The `-H` flag
says to include hidden directories in the recursive search.
This included a bit too much noise from the `node_modules` directory, so I want
to exclude that.
```bash
$ fd -I -H -E node_modules sitemap.xml
```
The `-E` flag can specify one-off directories to exclude from the search.
I can even specify a regex to make sure I capture files that look like
`sitemap-01.xml`, not just `sitemap.xml`.
```bash
$ fd -I -H -E node_modules 'sitemap.*.xml'
```
After familiarizing myself with a few flags, I'm able to take full advantage of
`fd`.