Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 将源目录复制到作为目录符号链接的目标_Bash_Directory_Symlink_Cp - Fatal编程技术网

Bash 将源目录复制到作为目录符号链接的目标

Bash 将源目录复制到作为目录符号链接的目标,bash,directory,symlink,cp,Bash,Directory,Symlink,Cp,如何将源目录的内容复制到目标目录中,其中目标目录是指向目录的符号链接?现在出现错误cp:无法用目录“source”覆盖非目录“symbolic link”。 以下是一个例子: vagrant@devbox:~/foo$ mkdir -p bin ; touch bin/something.txt vagrant@devbox:~/foo$ mkdir -p destination/bin vagrant@devbox:~/foo$ mkdir -p other-dir ; ln -s `pwd`

如何将源目录的内容复制到目标目录中,其中目标目录是指向目录的符号链接?现在出现错误
cp:无法用目录“source”覆盖非目录“symbolic link”。

以下是一个例子:

vagrant@devbox:~/foo$ mkdir -p bin ; touch bin/something.txt
vagrant@devbox:~/foo$ mkdir -p destination/bin
vagrant@devbox:~/foo$ mkdir -p other-dir ; ln -s `pwd`/destination/bin other-dir/bin
vagrant@devbox:~/foo$ tree
.
├── bin
│   └── something.txt
├── destination
│   └── bin
└── other-dir
    └── bin -> /home/vagrant/foo/destination/bin

5 directories, 1 file
vagrant@devbox:~/foo$ cp -v -r bin other-dir
cp: cannot overwrite non-directory 'other-dir/bin' with directory 'bin'
vagrant@devbox:~/foo$ cp -v -r -t other-dir bin
cp: cannot overwrite non-directory 'other-dir/bin' with directory 'bin'

找到了答案,这很奇怪:你复制的是“source/”而不是“source”。(为什么这样做有效?)


找到了答案,这很奇怪:你复制的是“source/”而不是“source”。(为什么这样做有效?)


单独使用GNU cp是不可能的。单独使用GNU cp是不可能的。
vagrant@devbox:~/foo$ cp -v -r bin/. other-dir/bin
'bin/./something.txt' -> 'other-dir/bin/./something.txt'
vagrant@devbox:~/foo$ cp -v -r -t other-dir/bin bin/.
'bin/./something.txt' -> 'other-dir/bin/./something.txt'
vagrant@devbox:~/foo$ tree
.
├── bin
│   └── something.txt
├── destination
│   └── bin
│       └── something.txt
└── other-dir
    └── bin -> /home/vagrant/foo/destination/bin

5 directories, 2 files