I want to retrieve specific files then cp
the result into another directory. It is all working, but my command seems to be executed a second time.
For example, I have a file a
and I want to cp
it into subdirectory test/
, so I run:
find . -mtime -1 -name a -exec cp {} test/ ';'
My file is copied into the subdirectory as I wanted but then I get this error message:
cp: './test/a' and 'test/a' are the same file
You have a race condition - first
find
finds./a
and copies it totest/a
, then it finds the newly copied./test/a
and tries to copy it again:You could avoid that by telling
find
not to descend into the target directory ex.