diff --git a/README.md b/README.md index 2d75177..f0289c5 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). -_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) diff --git a/unix/find-top-level-directories-matching-a-pattern.md b/unix/find-top-level-directories-matching-a-pattern.md new file mode 100644 index 0000000..d3b4f0e --- /dev/null +++ b/unix/find-top-level-directories-matching-a-pattern.md @@ -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.