Gnu find

From wikinotes
Revision as of 19:16, 18 April 2021 by Will (talk | contribs) (→‎Recipes)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Search files and directories.
This page is essentially a cookbook.

Also see bsd find.

Recipes

Suppress stderr in subshell

results=($({ find . -name .git; } 2>/dev/null))

Exclude Directories while searching for files

# search for *.txt files, not recursing into ~/.cache
find . \
    -not \( -path $HOME/.cache -prune \) \
    -name '*.txt'

Another less efficient alternative, that must glob match all files

find . \
    -not -path $HOME/.cache/* \
    -name '*.txt'