macos mac 上的 cp --parents 选项
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11246070/
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
cp --parents option on mac
提问by dmonopoly
On Linux, I have a --parents option available for the cp command so I can do
在 Linux 上,我有一个可用于 cp 命令的 --parents 选项,所以我可以这样做
cp --parents test/withintest/go.rb test2
http://www.gnu.org/software/coreutils/manual/html_node/cp-invocation.html
http://www.gnu.org/software/coreutils/manual/html_node/cp-invocation.html
On Mac, I do not have this option available. Is there a way to do this on Mac? Why is this option not available?
在 Mac 上,我没有此选项可用。有没有办法在 Mac 上做到这一点?为什么这个选项不可用?
PS. The purpose of --parents is the following:
附注。--parents 的目的如下:
‘--parents' Form the name of each destination file by appending to the target directory a slash and the specified name of the source file.
The last argument given to cp must be the name of an existing directory.
For example, the command:
cp --parents a/b/c existing_dir
copies the file a/b/c to existing_dir/a/b/c, creating any missing intermediate directories.
'--parents' 通过将斜杠和源文件的指定名称附加到目标目录来形成每个目标文件的名称。
给 cp 的最后一个参数必须是现有目录的名称。
例如,命令:
cp --parents a/b/c existing_dir
将文件 a/b/c 复制到 existing_dir/a/b/c,创建任何缺少的中间目录。
采纳答案by Echelon
回答by Stephan
This bothered me quite a lot as well. A workaround for this could be to use rsync.
这也让我非常困扰。对此的解决方法可能是使用 rsync。
rsync -R test/withintest/go.rb test2
has the same effect as cp --parents
and OS X comes standard with rsync.
具有cp --parents
与 OS X 标配 rsync相同的效果。
回答by Kara
You can install the GNU version of cp
using MacPorts.
您可以cp
使用MacPorts安装 GNU 版本。
After MacPorts is installed you can install the coreutils packages:
安装 MacPorts 后,您可以安装 coreutils 包:
sudo port install coreutils
Then you will be able to use the GNU version cp
and other core utilitites (ls
, date
, cat
, etc.) by prefixing the command with a g
:
然后,你就可以使用GNU版本cp
和其他核心utilitites( ,,通过附加了一个命令等):ls
date
cat
g
gcp --parents test/withintest/go.rb test2
If you want these GNU versions to be used by default you can add the GNU bin update your path. Add the following to your ~/.bash_profile
:
如果您希望默认使用这些 GNU 版本,您可以添加 GNU bin 更新您的路径。将以下内容添加到您的~/.bash_profile
:
export PATH="/opt/local/libexec/gnubin:$PATH"
回答by vikrantt
I would not replace mac cp with GNU cp. I would also not used ditto because it is not cross-platform. Instead use cross-platform tools, such as rsync:
我不会用 GNU cp 替换 mac cp。我也不会使用同上,因为它不是跨平台的。而是使用跨平台工具,例如 rsync:
rsync <srcDir/srcFile> <dst>
Result: dst/srcDir/srcFile
结果:dst/srcDir/srcFile
回答by Martin Peter
The Homebrew way:
自制方式:
Install coreutils
安装 coreutils
brew install coreutils
Use the GNU
g- prefixed command
使用GNU
g- 前缀命令
gcp --parents test/withintest/go.rb test2