AZ.dev

find Essentials Cheat Sheet

Linux & Shell

The find commands you reach for every day, by name, type, time and size, plus the actions and combinators that turn a match into work done.

10 cards | macos: 15 posix: any gnu-findutils: 4.9

By name and type

Find by name, current directory down

find . -name "*.log"

Quote the pattern or the shell expands it before find sees it.

Find by name, case-insensitive

find . -iname "*.log"

Files only

find . -type f

Directories only

find . -type d

By time and size

Bigger than 10 MB

find . -size +10M

+ is bigger than, - is smaller than. Units: k, M, G.

Actions

Find and delete

find . -name "*.tmp" -delete

-delete must come last. Put it before -name and it deletes everything.

Combining tests

Match either pattern

find . -name "*.js" -o -name "*.ts"

-a is and (implied between tests, so you can leave it out), -o is or, ! negates.

Modern alternative

Same search with fd

fd XYZ

Replaces find . -name "*XYZ*". Install with brew install fd.