If you try to copy a source directory into a symlink to a target directory, you may get an error like:
cp: cannot overwrite non-directory 'symbolic-link' with directory 'source'
.
The solution is to actually copy the .
directory of your source directory.
This is not obvious based on the GNU coreutils FAQ or the man page.
Below is an example to explain:
vagrant@devbox:~/foo$ mkdir bin
vagrant@devbox:~/foo$ touch bin/script.sh
vagrant@devbox:~/foo$ mkdir -p new-destination/bin
vagrant@devbox:~/foo$ mkdir link-dir
vagrant@devbox:~/foo$ ln -s `pwd`/new-destination/bin link-dir/bin
vagrant@devbox:~/foo$ tree
.
├── bin
│ └── script.sh
├── new-destination
│ └── bin
└── link-dir
└── bin -> /home/vagrant/foo/new-destination/bin
5 directories, 1 file
vagrant@devbox:~/foo$ cp -v -r bin link-dir
cp: cannot overwrite non-directory 'link-dir/bin' with directory 'bin'
vagrant@devbox:~/foo$ cp -v -r -t link-dir bin
cp: cannot overwrite non-directory 'link-dir/bin' with directory 'bin'
vagrant@devbox:~/foo$ cp -v -r bin link-dir/bin
'bin' -> 'link-dir/bin/bin'
'bin/script.sh' -> 'link-dir/bin/bin/script.sh'
vagrant@devbox:~/foo$ rm -rf link-dir/bin/bin
vagrant@devbox:~/foo$ cp -v -r bin/. link-dir/bin
'bin/./script.sh' -> 'link-dir/bin/./script.sh'
vagrant@devbox:~/foo$ cp -v -r -t link-dir/bin bin/.
'bin/./script.sh' -> 'link-dir/bin/./script.sh'
vagrant@devbox:~/foo$ tree
.
├── bin
│ └── script.sh
├── new-destination
│ └── bin
│ └── script.sh
└── link-dir
└── bin -> /home/vagrant/foo/new-destination/bin
5 directories, 2 files
As you can see, using cp -r bin/. link-dir/bin
works the way you intend without a 'non-directory' error.