最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

cp

旗下网站admin12浏览0评论

cp

cp

cp -a无法覆盖符号链接目录(cp -a cannot overwrite symlinked directory)

我有一个包含符号链接文件夹的文件夹。

root |- Current document -> version 2 document |- Current folder -> version 2 folder |- Archives |- version 1 document |- version 1 folder |- ... |- version 2 document |- version 2 folder |- ...

当我使用cp -r复制此目录时,文件夹会复制,但由于-r遵循符号链接,因此版本2将被复制两次。

当我使用cp -R复制此目录时,该文件夹第一次复制并保留符号链接。 但是,在第二个副本上,它无法覆盖该文件夹,说明:

cp: cannot overwrite directory 'Current folder' with 'Current folder'

我也试过cp -a == cp -pPR以及-f版本( cp -fR和cp -fa )

我认为通过遵循符号链接来查看Current Folder是否是文件夹,然后无法用符号链接覆盖符号链接(它认为它是一个文件夹)。

使用符号链接文件夹一致地复制和覆盖文件夹的正确命令是什么?

I have a folder that contains symlinked folders.

root |- Current document -> version 2 document |- Current folder -> version 2 folder |- Archives |- version 1 document |- version 1 folder |- ... |- version 2 document |- version 2 folder |- ...

When I copy this directory with cp -r, the folder copies, but since -r follows symlinks, version 2 is copied twice.

When I copy this directory with cp -R, the folder copies fine the first time and preserves the symlinks. However, on the second copy, it is unable to overwrite the folder, stating:

cp: cannot overwrite directory 'Current folder' with 'Current folder'

I also tried cp -a == cp -pPR as well as the -f versions (cp -fR and cp -fa)

I think it's tests to see if Current Folder is a folder by following symlinks and then fails to overwrite the symlink (which it thinks it's a folder) with a symlink.

What's the right command to consistently copy and overwrite a folder with symlinked folders?

最满意答案

在OSX上,使用ditto

它具有与osx复制/粘贴相同的行为。

PS一个你可能需要注意的问题:

cp -a foo bar

将文件夹foo /移动到bar /(即bar / foo / file1,bar / foo / file2)

ditto foo bar

将文件夹foo /的内容移动到bar(即bar / file1,bar / file2)

On OSX, use ditto

It has the same behavior as osx copy/paste.

P.S. One gotcha that you might want to watch out for:

cp -a foo bar

will move the folder foo/ into bar/ (ie bar/foo/file1, bar/foo/file2)

ditto foo bar

will move the contents of folder foo/ into bar (ie bar/file1, bar/file2)

发布评论

评论列表(0)

  1. 暂无评论