macos 如何在 OS X 10.7.3 中复制目录?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9794694/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to copy directories in OS X 10.7.3?
提问by hjaved
Hi I'm trying to copy my rails_projects directory from haseebjaved/Desktop/rails_projects to my home directory, which is haseebjaved.
嗨,我正在尝试将我的 rails_projects 目录从 haseebjaved/Desktop/rails_projects 复制到我的主目录,即 haseebjaved。
How can I do this via the Command Line?
如何通过命令行执行此操作?
Also, can I see my home directory on the UI or only via the Command Line in Mac OS X?
另外,我可以在 UI 上查看我的主目录,还是只能通过 Mac OS X 中的命令行查看?
Is it possible to copy directories to and from my home directory via the UI? Or only via Command Line?
是否可以通过 UI 将目录复制到我的主目录或从我的主目录复制?还是只能通过命令行?
Thank you
谢谢
回答by Andy Friese
Is there something special with that directory or are you really just asking how to copy directories?
该目录有什么特别之处,还是您真的只是在问如何复制目录?
Copy recursively via CLI:
通过 CLI 递归复制:
cp -R <sourcedir> <destdir>
If you're only seeing the files under the sourcedir
being copied (instead of sourcedir
as well), that's happening because you kept the trailing slash for sourcedir
:
如果您只看到sourcedir
正在复制的文件(而不是sourcedir
同时复制),则发生这种情况是因为您保留了结尾的斜杠sourcedir
:
cp -R <sourcedir>/ <destdir>
The above only copies the files and their directories inside of sourcedir
. Typically, you want to include the directory you're copying, so drop the trailing slash:
以上仅复制sourcedir
. 通常,您希望包含要复制的目录,因此删除尾部斜杠:
cp -R <sourcedir> <destdir>
回答by Gary Davies
tl;dr
tl;博士
cp -R "/src/project 1/App" "/src/project 2"
Explanation:
解释:
Using quotes will cater for spaces in the directory names
使用引号将迎合目录名称中的空格
cp -R "/src/project 1/App" "/src/project 2"
If the App directory is specified in the destination directory:
如果在目标目录中指定了 App 目录:
cp -R "/src/project 1/App" "/src/project 2/App"
and "/src/project 2/App" already exists the result will be "/src/project 2/App/App"
并且“/src/project 2/App”已经存在,结果将是“/src/project 2/App/App”
Best not to specify the directory copied in the destination so that the command can be repeated over and over with the expected result.
最好不要指定复制到目的地的目录,这样命令可以一遍遍地重复执行,得到预期的结果。
Inside a bash script:
在 bash 脚本中:
cp -R "/App" ""