1

Example:

I created a symbolic link into my /usr/local/bin folder using

sudo ln -s ~/Desktop/package/Application/tool1
sudo ln -s ~/Desktop/package/Application/tool2
…

I would like to move my Application folder (and all its tools) to /package/Application (basically outside the Users parent directory). Is it possible to have the original symbolic links point to its corresponding tool in its new location?

2 Answers 2

2

No. Symbolic links will continue pointing to the same location and become dangling symlinks. To make them point to the new location you can either remove them and recreate them correctly or make a double indirection: create symlinks from the current location of the tools to the new one so that the symlinks in /usr/local/bin continue to point (though indirectly this time) to the correct location.

0

If you are on a filesystem that supports reflinking you could consider using ref links instead. So instead of:

ln -s oldloc/foo tools/bar
mv oldloc newloc
# oh dear broken link

Use:

cp --reflink=always oldloc/foo tools/bar
# oldloc/foo and tools/bar point to the same disk extents
mv oldloc newloc
# newloc is just a rename so oldloc/foo and tools/bar still point to the same disk extents

There are still some caveats. If you install a new version of 'foo' then tools/bar is NOT updated.

This is a major problem for most uses of links. Also this kind of reflinking does not work for directories.

You could also consider using hardlinks. Hardlinks always point to the same file (or rather the same underlying disk locations).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .