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