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

@@ -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).
_1253 TILs and counting..._
_1254 TILs and counting..._
---
@@ -1200,6 +1200,7 @@ _1253 TILs and counting..._
- [Exclude Certain Files From An rsync Run](unix/exclude-certain-files-from-an-rsync-run.md)
- [Figure Out The Week Of The Year From The Terminal](unix/figure-out-the-week-of-the-year-from-the-terminal.md)
- [File Type Info With File](unix/file-type-info-with-file.md)
- [Find All Files Matching A Name With fd](unix/find-all-files-matching-a-name-with-fd.md)
- [Find A File Installed By Brew](unix/find-a-file-installed-by-brew.md)
- [Find Files With fd](unix/find-files-with-fd.md)
- [Find Newer Files](unix/find-newer-files.md)

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`.