I have a find
command that I run to find files whose names contain foo
.
I want to skip the .git
directory. The command below works except it prints an
annoying .git
any time it skips a .git
directory:
find . ( -name .git ) -prune -o -name '*foo*'
How can I prevent the skipped .git
directories from
printing to the standard output?
So just for better visibility:
find -name '.git*' -prune -o -name '*foo*' -print
This also omits .gitignore files; note the trailing -print to omit printing, -prune stops descending into it but without -print prints it nevertheless. Twisted C;
find . -not -wholename "./.git*" -name "*foo*"
or, more strictly, if you don't want to see .git/ but do want to search in other dirs whose name also begins with .git (.git-foo/bar/...
)
find . -not -wholename "./.git" -not -wholename "./.git/*" -name "*foo*"
If your .git/ directories may not always necessarily be located at the top-level of your search directory, you will want to use -not -wholename ".*/.git"
and -not -wholename ".*/.git/*"
.
A bit odder but more efficient because it prunes the whole .git
dir:
find . -not \( -wholename "./.git" -prune \) -name "*foo*"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With