Create a symbolic link relative to the current directory

Here's what's happening. If you make a symlink with a relative path, the symlink will be relative. Symlinks just store the paths that you give them. They never resolve paths to full paths. Running

$ pwd
/usr/bin
$ ln -s ls /usr/bin/ls2

creates a symlink named ls2 in /usr/bin to ls(viz. /usr/bin/ls) relative to the directory that the symlink is in (/usr/bin). The above command would create a functional symlink from any directory.

$ pwd
/home/me
$ ln -s ls /usr/bin/ls2

If you moved the symlink to a different directory, it would cease to point to the file at /usr/bin/ls.

You are making a symlink that points to Data, and naming it Data. It is pointing to itself. You have to make a symlink with the absolute path of the directory.

ln -s "$(realpath Data)" ~/Data

I was having the same problem. Google led to this answer but the simplest solution is not documented here:

ln -sT 

-T does the trick

man ln:

-T, --no-target-directory
    treat LINK_NAME as a normal file always

Just adding this here so anyone with the same question may find this :)


ln's behavior with relative paths is unintuitive. To restore sanity, use the -r flag.

cd /run/media/name/exhdd
ln -sr Data/ ~/Data

Explanation:

   -r, --relative
          create symbolic links relative to link location

What it means is that ln will do what you expect. It will take into account what directory you are in, what directory the target is in, and construct a path relative to the directory the link will be in. The default behavior (without -r) is to interpret the first parameter (target) literally, in which case you have to construct the path yourself so that it is valid at the link's directory.

Alternatively, use an absolute path, as mentioned by @SmithJohn

ln -s "$(realpath Data)" ~/Data #bash shell

or

ln -s "(realpath Data)" ~/Data #fish shell