Search code examples
unixsymlink

Is there a way to edit a symbolic link without deleting it first?


So I created a symbolic link:

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?


Solution

  • 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.