Why does my find command get executed two times?
You have a race condition - first find
finds ./a
and copies it to test/a
, then it finds the newly copied ./test/a
and tries to copy it again:
$ find . -mtime -1 -name a -print -exec cp -v {} test/ ';'
./a
'./a' -> 'test/a'
./test/a
cp: './test/a' and 'test/a' are the same file
You could avoid that by telling find
not to descend into the target directory ex.
find . -path ./test -prune -o -mtime -1 -name a -exec cp {} test/ ';'