bashshellsedpipefind-util

Why is my `find` command giving me errors relating to ignored directories?


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.


Solution

  • why is the find searching in the .git directory?

    GNU find is clever and supports several optimizations over a naive implementation:

    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