Execution Patterns
Simple -exec with \; — one invocation per file
find ~/atelier/_bibliotheca/domus-captures/docs/modules/ROOT/partials -name "*.adoc" -type f \
-exec head -1 {} \;
Batch -exec with + — one invocation, many files (faster)
find ~/atelier/_bibliotheca/domus-captures/docs/modules/ROOT/pages -name "*.adoc" -type f \
-exec wc -l {} +
-exec sh -c for complex commands — grep first line for missing :description:
find ~/atelier/_bibliotheca/domus-captures/docs/modules/ROOT/pages -name "*.adoc" -type f \
-exec sh -c '
for f; do
if ! head -5 "$f" | grep -q ":description:"; then
echo "MISSING :description: — $f"
fi
done
' _ {} +
Prune a directory — skip .git entirely
find ~/atelier/_bibliotheca/domus-captures -path '*/.git' -prune -o -name "*.adoc" -type f -print
Prune multiple directories
find ~/atelier/_bibliotheca/domus-captures \
\( -path '*/.git' -o -path '*/node_modules' -o -path '*/build' \) -prune \
-o -type f -name "*.adoc" -print | head -20
-print0 to xargs — null-delimited for spaces in filenames
find ~/atelier/_bibliotheca/domus-captures/docs -name "*.adoc" -type f -print0 | \
xargs -0 wc -l | tail -1
xargs with parallel execution — 4 workers
find ~/atelier/_bibliotheca/domus-captures/docs -name "*.adoc" -type f -print0 | \
xargs -0 -P4 -I{} head -1 {}
-delete — remove empty files (safer than rm)
# Dry run first — just list what would be deleted
find /tmp -name "*.tmp" -empty -type f -print
# Then delete
# find /tmp -name "*.tmp" -empty -type f -delete
Copy found files to a staging directory
mkdir -p /tmp/find-staging
find ~/atelier/_bibliotheca/domus-captures/docs/modules/ROOT/partials/codex/find \
-name "*.adoc" -type f -exec cp {} /tmp/find-staging/ \;
ls /tmp/find-staging/
-exec with \; vs + — timing comparison
# Slow — spawns grep once per file
# find /etc -name "*.conf" -exec grep -l "Port" {} \;
# Fast — spawns grep once with all files
find /etc -name "*.conf" -type f -exec grep -l "Port" {} + 2>/dev/null