A relative symlink is relative to its parent directory, that's irrelevant from the current directory of any process or the home directory of any user.
For instance, if /some/dir/link
is a symlink to ../foo/bar
, then that's a symlink to /some/dir/../foo/bar
(/some/foo/bar
if /some/dir
is not itself a symlink), regardless of what your current or home directory is.
If you want to create a new symlink to a file relative to the current directory (for instance the bin/ls
file in your current /home/stephane
directory), then you can do (in POSIX-like shells or fish
):
ln -s -- "$PWD/bin/ls" /some/dir/link
Which would create an absolute symlink (to /home/stephane/bin/ls
). To create a relative symlink, you'd need:
ln -s ../../home/stephane/bin/ls /some/dir/link
(assuming /some
and /some/dir
are not themselves symlinks)
GNU ln
has a -r
option to help you compute that path:
ln -rs bin/ls /some/dir/link
(which would create the same symlink to ../../home/stephane/bin/ls
).