I have a directory, dir1
which contains many files whose names end in either .jpg
or .png
. I want to copy all the .png
files to dir2
which is empty.
This command works:
find dir1 -name '*.png' -exec cp {} dir2 \;
but this command doesn't:
find dir1 -name '*.png' -exec cp {} dir2 +
find: missing argument to `-exec'
I also tried:
find dir1 -name '*.png' -exec cp {} -t dir2 +
find: missing argument to `-exec'
and:
find dir1 -name '*.png' -exec cp {} dir2 \+
find: missing argument to `-exec'
After looking at this page, I even tried:
find dir1 -name '*.png' -exec cp {} dir2 {} +
find: Only one instance of {} is supported with -exec ... +
This page says that:
-exec {} + was added in [version] 4.2.12 in 2005
My version of find
is 4.4.2.
What am I doing wrong?
Best Answer
Thanks to 'steeldriver', I've worked out that the answer is because POSIX specification forbids anything from being between
{}
and+
after-exec
.