How to prevent detection of fingerprints of .git folders?

I have a command findthat I run to find files whose names contain foo.

I want to skip the directory .git. The following command except , it prints annoying .gitanytime it skips a directory .git:

find . ( -name .git ) -prune -o -name '*foo*'

How can I prevent skipped directories .gitfrom printing to standard output?

+5
source share
3 answers

Try the following:

find . -name '*foo*' | grep -v '\.git'

It will still pass in the .git directory, but will not display them. Or you can combine your version:

find . ( -name .git ) -prune -o -name '*foo*' | grep -v '\.git'

You can also do this without grep:

find . ( -name .git ) -prune -printf '' -o -name '*foo*' -print
+1
source

So simple for better visibility:

find -name '.git*' -prune -o -name '*foo*' -print

.gitignore ; -print, , - , , -print . Twisted C;

+8
find . -not -wholename "./.git*" -name "*foo*"

or, more strictly, if you do not want to see .git /, but want to search in other dirs, whose name also begins with .git ( .git-foo/bar/...)

find . -not -wholename "./.git" -not -wholename "./.git/*" -name "*foo*"

A bit more complicated, but more efficient, because it truncates the entire .gitdir:

find . -not \( -wholename "./.git" -prune \) -name "*foo*"
+2
source

All Articles