Answers:
该目录是否有特殊之处,或者您真的只是在问如何复制目录?
通过CLI递归复制:
cp -R <sourcedir> <destdir>
如果您只看到sourcedir
正在复制的文件(而不是复制文件sourcedir
),则发生这种情况是因为您将斜杠保留为sourcedir
:
cp -R <sourcedir>/ <destdir>
上面的代码仅复制内的文件及其目录sourcedir
。通常,您要包括要复制的目录,因此请在结尾加上斜杠:
cp -R <sourcedir> <destdir>
cp -r ~/Desktop/rails_projects ~
是您想要的
cp
:-R If source_file designates a directory, cp copies the directory and the entire subtree connected at that point. **If the source_file ends in a /, the contents of the directory are copied rather than the directory itself.** This option also causes symbolic links to be copied, rather than indirected through, and for cp to create special files rather than copying them as normal files. Created directories have the same mode as the corresponding source directory, unmodified by the process' umask.
tl; dr
cp -R "/src/project 1/App" "/src/project 2"
说明:
使用引号将满足目录名称中的空格
cp -R "/src/project 1/App" "/src/project 2"
如果在目标目录中指定了App目录:
cp -R "/src/project 1/App" "/src/project 2/App"
并且“ / src / project 2 / App”已经存在,结果将是“ / src / project 2 / App / App”
最好不要指定在目标中复制的目录,以便可以反复执行命令以得到预期的结果。
在bash脚本中:
cp -R "${1}/App" "${2}"