linuxln

How can I avoid 'are the same file' error when using 'ln' in Linux?


I'm trying to link a directory to another location. Using the following command

ln -sf . dot

succeeds the first time, but it returns an error the second time:

ln -sf . dot

Output:

ln: '.' and 'dot/.' are the same file

This was on Ubuntu 16.04.12 (Xenial Xerus).

How can I avoid this error?


Solution

  • You can use ln -n to not dereference the existing symbolic link. See man ln.

    ln -nsf . dot