Reputation:
I have directory a
that is symlinked somewhere. I want to copy its contents to directory b
. Doesn't the following simple solution break in some corner cases (e.g. hidden files, exotic characters in filenames, etc.)?
mkdir b
cp -rt b a/*
Upvotes: 2
Views: 1303
Reputation: 34954
Simply adding a trailing '/' will follow the symlink and copy the contents rather than the link itself.
cp -a symlink/ dest
Bash globbing does not choke on special characters in filenames. This is the reason to use globbing, rather than parsing the output of a command such as ls
. The following would also be fine.
shopt -s dotglob
mkdir -p dest
cp -a symlink/* dest/
Upvotes: 3