Solution to error 'find: missing argument to -exec' with find -exec cp {} TARGET_DIR + [closed]

霸气de小男生 提交于 2019-12-19 07:11:31

问题


I was getting ready to post this as a question, but after fiddling around with it a little longer, I found the solution. So I thought I would go ahead and post it here in case it helps someone else.

I had trouble with find -exec cmd +. I got the error:

$ find ./ -name "*JIM*" -exec cp {} $TARGET_DIR +
find: missing argument to `-exec'

It worked if I used

$ find ./ -name "*JIM*" -exec cp {} $TARGET_DIR \;

But I did't want to use that because it forks a new process for every file found.

And it worked if I used

$ find ./ -name "*JIM*" -exec ls {} +

It lists all of the files that I want to copy. But -exec cp {} $TARGET_DIR + didn't work.

The solution I found is:

$ find ./ -name "*JIM*" -exec cp --target-directory=$TARGET_DIR {} +

Where --target-directory= could also be replaced with -t

Hope this helps.


回答1:


As mentioned in the opening post, the solution I found is:

$ find ./ -name "*JIM*" -exec cp --target-directory=$TARGET_DIR {} +

Where --target-directory= could also be replaced with -t



来源:https://stackoverflow.com/questions/12060557/solution-to-error-find-missing-argument-to-exec-with-find-exec-cp-target

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!