Is there a way to edit a symlink without deleting it first?

Andrew picture Andrew · Nov 13, 2009 · Viewed 74.1k times · Source

So I created a symlink:

ln -s /location/to/link linkname

Now I want to change the location that the symlink links to. How do I do that? is there a way to do it without deleting it first?

Answer

martin clayton picture martin clayton · Nov 13, 2009

You could create the new link with a different name, then move it to replace the old link.

ln -s /location/to/link linkname

Later

ln -s /location/to/link2 newlink
mv newlink linkname

If newlink and linkname are on the same physical device the mv should be atomic.