将找到的目录复制到使用指定参数和找到的目录构建的路径

时间:2016-08-12 12:05:33

标签: linux bash find exec cp

我有以下bash脚本:

foo/bar

我们的想法是在cd root_folder && find folder1 folder2 -name "doc" -exec cp -r --parents {} $1{} \; doc下找到名为folder1的所有文件夹,并将结构从folder2复制到用户指定的路径&#39 ; s参数(以及root_folder的所有内容)。

所以例如

doc

变为:

root_folder/folder1/other_folder/doc

只要我没有让用户指定要复制到的文件夹,即如果我没有$1/folder1/other_folder/doc ,则此脚本可以正常运行。但是,当我拥有它时,我收到错误:

$1

尽管事实上1)我已经确定预先存在指定的文件夹,并且2)如果我输出要复制到的完整路径,它看起来应该完全正确,即cp: with --parents, the destination must be a directory Try `cp --help' for more information.

我还尝试在$1/folder1/other_folder/doc之后添加/来制作$1,但这会使正斜杠过多,使路径包含$1/{},这显然是错误的

我在这里缺少什么?

0 个答案:

没有答案