on mac using gnu tools
Im not sure whats happening but it seems piping the output of find to xargs has some issue with touching files with the same name that appear in the directory structure in different places
dir -- dirone ---- myfile.txt ---- otherfile.txt -- dirtwo ---- myfile.txt
When I run this command I get a permissions denied error:
find dir -name "myfile.txt" | xargs -0 -I FILE sh -c "ls FILE"
I cant even touch/ls the file. If I access "otherfile.txt" of which there is one I see no issues
find dir -name "otherfile.txt" | xargs -0 -I FILE sh -c "ls FILE"
Is there some kind of race condition or something? I eventually want to modify the files with
sed -i but I cant even ls them. I dont understand because the full file path is being passed to xargs so it should have the complete path making the fact that its the same name not matter right?
EDIT: OK still dont understand why I was getting perms errors but this seems to work:
find dir -name "otherfile.txt" -type file -print0 | xargs -0 -I FILE sh -c "ls FILE"
-0 also worked, I'm not sure which way is better/safer?