I have this find command:
find . -type f -not -path '**/.git/**' -not -path '**/node_modules/**' | xargs sed -i '' s/typescript-library-skeleton/xxx/g;
for some reason it's giving me these warnings/errors:
find: ./.git/objects/3c: No such file or directory
find: ./.git/objects/3f: No such file or directory
find: ./.git/objects/41: No such file or directory
I even tried using:
-not -path '**/.git/objects/**'
and got the same thing. Anybody know why the find is searching in the .git
directory? Seems weird.
why is the find searching in the .git directory?
GNU find
is clever and supports several optimizations over a naive implementation:
-size +512b -name '*.txt'
and check the name first, because querying the size will require a second syscall. -type d
or for recursing.(-B -or -C) -and -A
so that if the checks are equally costly and free of side effects, the -A
will be evaluated first, hoping to reject the file after 1 test instead of 2.However, it is not yet clever enough to realize that -not -path '*/.git/*'
means that if you find a directory .git
then you don't even need to recurse into it because all files inside will fail to match.
Instead, it dutifully recurses, finds each file and matches it against the pattern as if it was a black box.
To explicitly tell it to skip a directory entirely, you can instead use -prune
. See How to exclude a directory in find . command