How to change the target of a symbolic link in Linux

The common way is to delete the original symlink then re-create it.

rm symlink; ln -s target symlink

But if you want to do it more conveniently and efficiently, you can force ln command to change the target of the soft link without deleting the old one explicitly. For example:

# original symlink
$ ln -s /path/to/target old_symlink

# change to the new symlink
$ ln -fs /path/to/target new_symlink

References

  • Linux Man pages
comments powered by Disqus