If the symlink targets are directories, you need to add the -T
flag to the mv
command, otherwise it moves the new symlink in to the target directory of the old symlink.
Example of atomically switching a website to a new version:
Original setup - website is stored in www1
directory, vhost pointing at www
symlink:
ln -s www1 www
Browse to website, see old version.
Put new website files in new www2
directory.
Set up new symlink to new website:
ln -s www_new www2
Move www
symlink to directory of new website:
mv -T www_new www
Browse to website, see new version immediately.