I want to list all the files except those inside .git/
directory with the find
command only.
I tried this:
$ find . -path .git -prune -type f
$
it returned 0 files (instead of the 2 I have) so I tried this :
$ find . -not -path .git -type f | grep -c '\.git'
1770
$
I don't understand why none of these is working, can you help ?
EDIT0 : Thanks to @icarus, I see that the paths must be preceded by ./
and that I was missing the OR
operator consequently, this command works :
$ find . -path ./.git -prune -o -type f | grep '\.git'
./.git
./.gitignore
$
EDIT1 : Why does that other command does not work ?
$ find . -not -path ./.git -a -type f | grep -c '\.git'
1770
$
EDIT2 : One last question : why does the -prune
predicate need a -o -print
not to print the ./.git
and ./.gitignore
results in the command below :
$ find . -name ".git*" -prune | grep git
./.git
./.gitignore
$ find . -name ".git*" -prune -o -print | grep -c git
0
EDIT3 : Thank you @rastafile :
$ find . -name ".git*" -prune | grep git
./.git
./.gitignore
$ find . -name ".git*" -prune -print | grep git
./.git
./.gitignore
$ find . -name ".git*" -prune -o -print | grep git
$
It seems the GNU find -prune
predicate calls -print
implicitly when the previous expression is true :
If the expression contains no actions other than -prune, -print is performed on all files for which the expression is true.
In conclusion : The command I need is :
$ find . -name ".git*" -prune -o -type f -print
Thank you everyone.
find
if there is none, even for '-prune'. So you have to steal the builtin '-print' it from '-prune'.