Find files by name pattern

Read-only
What do risk levels mean?
Read-only
Inspects state without changing anything.
Low risk
Reversible with a routine follow-up command.
Medium risk
Changes state; undo path documented.
Destructive
Deletes or overwrites; confirmation required.

Searches a directory tree for files whose names match a glob pattern, such as every "*.log" file or a misplaced config file.

filessearchfindglob

Parameters

Directory to search under.

Glob pattern to match file names, e.g. "*.log".

Commands

List every file under the directory whose name matches the pattern

find "." -type f -name "<pattern>"

Verification

find "." -type f -name "<pattern>" | wc -l

A count of matching files; zero means nothing matched the pattern.

Undo

Not undoable

This recipe only searches for files and changes nothing.

Pitfalls

  • Quote the pattern so the shell does not expand the glob before find sees it.
  • Use -iname (or -Filter with PowerShell's case-insensitive default) when the file's exact casing is unknown.

Related