Choosing a tool

fd for a quick match

fd '\.ts$' src

Input

src/app.ts
src/app.test.ts
src/lib/util.ts
src/readme.md

Output

src/app.ts
src/app.test.ts
src/lib/util.ts

Finds files with a regex. fd respects gitignore and skips hidden files by default; see fd.

fd with a command

fd -e ts -x wc -l

Input

src/app.ts
src/app.test.ts
src/lib/util.ts

Output

10 src/app.ts
20 src/app.test.ts
5 src/lib/util.ts

Runs a command on each match. -x passes the path as {}; see fd.

find by name

find . -name '*.ts' -not -path '*/node_modules/*'

Input

src/app.ts
src/app.test.ts
node_modules/pkg/index.ts

Output

./src/app.ts
./src/app.test.ts

Finds files by name portably. find needs explicit pruning and ignores; see find.

find with exec

find . -name '*.ts' -exec wc -l {} +

Input

src/app.ts
src/app.test.ts

Output

10 ./src/app.ts
20 ./src/app.test.ts

Runs a command on matched files. -exec ... + batches matches into one call instead of one per file. See find.

0 Comments for this cheatsheet. Write yours!