brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: ln -sr makes a relative symlink, so the link keeps working when you move the tree

Linux
~/tips/tip-linux-ln-sr-relative-symlink

ln -sr /srv/site/shared/uploads /srv/site/current/uploads

Create a symlink with a relative path without counting the dots yourself.

A symlink with an absolute path breaks as soon as you move the folder, mount it somewhere else or copy it into a container. Relative links survive that, but working out how many ../ you need is annoying.

ln -sr /srv/site/shared/uploads /srv/site/current/uploads
ls -l /srv/site/current/uploads

With -r, GNU ln works out the relative path for you. You type two normal paths, and the link that comes out points to ../shared/uploads. Move the whole /srv/site folder and the link still finds its target.

It works with relative arguments as well, as long as they make sense from where you are. I prefer full paths with -r because it is easy to read back which file is the target and which is the link.

The -r option only does something together with -s, since a hard link has no path of its own. It is also a GNU option: macOS and BusyBox ln do not have it.

A relative link is only relative to where the link itself lives. If you later move the link but not its target, or the other way round, it breaks just like an absolute one. Check for broken links afterwards with find /srv/site -xtype l.

Further reading: ln(1) manual page

More Linux tips a2query -m rewrite renice -n 10 -p 4242 cat config.yml | xsel -ib xvfb-run -a your-program --some-flag dpkg --get-selections > packages.txt All Linux tips (261) All topics

Link