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?
Note that removing a symbolic link does not affect the file it points to. Before removing a file, you can verify whether it is a symbolic link using the ls -l command. It will also show you the file or directory that it points to.
To get around this it is possible to use the -f flag to 'force' the ln command to recreate the symlink without deleting it first. There is a slight niggle here in that we also need to supply the -n flag (or --no-dereference) to treat the destination that is a symlink to a directory as if it were a normal file.
A symbolic link encountered in the tree traversal is copied instead of the file pointed to by the symbolic link. If source_file designates a directory, cp copies the directory and the entire subtree connected at that point. This option causes cp to create special files rather than copying them as normal files.
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.
Try ln -sf new_destination linkname
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With