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

Add Find Top-Level Directories Matching A Pattern as a Unix TIL

This commit is contained in:
jbranchaud
2024-05-19 10:08:45 -05:00
parent 44e626a086
commit 39614e975e
2 changed files with 38 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).
_1431 TILs and counting..._
_1432 TILs and counting..._
---
@@ -1377,6 +1377,7 @@ _1431 TILs and counting..._
- [Find Files With fd](unix/find-files-with-fd.md)
- [Find Newer Files](unix/find-newer-files.md)
- [Find Occurrences Of Multiple Values With Ripgrep](unix/find-occurrences-of-multiple-values-with-ripgrep.md)
- [Find Top-Level Directories Matching A Pattern](unix/find-top-level-directories-matching-a-pattern.md)
- [Fix Unlinked Node Binaries With asdf](unix/fix-unlinked-node-binaries-with-asdf.md)
- [Forward Multiple Ports Over SSH](unix/forward-multiple-ports-over-ssh.md)
- [Generate A SAML Key And Certificate Pair](unix/generate-a-saml-key-and-certificate-pair.md)

View File

@@ -0,0 +1,36 @@
# Find Top-Level Directories Matching A Pattern
I like using [`fd`](https://github.com/sharkdp/fd) as an alternative to `find`.
In my experience it is more intuitive to use. For instance, I wanted to find
all the top-level directories in my current directory that contained the word
`next`. I was able to get the command mostly right by guessing the flags, only
checking the man page once.
On my first attempt, it prompted me with a suggestion for a flag that wasn't
quite right. I tried `--depth`, but it should have been `--maxdepth`.
```bash
$ fd --depth 0 next ./
error: Found argument '--depth' which wasn't expected, or isn't valid in this context
Did you mean --maxdepth?
```
Then I checked the man page for how to specify the file type as _directory_ --
using `-t` or `--type` with `d`.
And here is the command that gets me all top-level directories matching `next`
in my current directory:
```bash
$ fd --maxdepth 1 --type d next ./
bookshelf-nextjs-prisma-postgres
bookshelf-prisma-nextjs-planetscale
my-next-app
next-bookshelf
next-personal-site
next-sanity-v3-example
try-trpc-next
```
See `man fd` for more details.