Assuming you are in directory /path/to/common/root
:
$ pwd
/path/to/common/root
which has a subdirectory build-tools/20.0.0/lib
:
$ readlink -e build-tools/20.0.0/lib
/path/to/common/root/build-tools/20.0.0/lib
and subdirectory platform-tools
, but no file or directory platform-tools/lib
:
$ ls -d platform-tools
platform-tools
$ ls platform-tools/lib
ls: cannot access platform-tools/lib: No such file or directory
and you want to make platform-tools/lib
a symlink to build-tools/20.0.0/lib
, then you can either make it an absolute link:
$ ln -s /path/to/common/root/build-tools/20.0.0/lib platform-tools/lib
$ ls -l platform-tools/lib
lrwxrwxrwx 1 user user 72 Sep 16 12:57 platform-tools/lib -> /path/to/common/root/build-tools/20.0.0/lib
$ readlink -e platform-tools/lib
/path/to/common/root/build-tools/20.0.0/lib
or you can make it a relative link:
$ ln -s ../build-tools/20.0.0/lib platform-tools/lib
$ ls -l platform-tools/lib
lrwxrwxrwx 1 user user 25 Sep 16 12:58 platform-tools/lib -> ../build-tools/20.0.0/lib
$ readlink -e platform-tools/lib
/path/to/common/root/build-tools/20.0.0/lib
while noting that the relative link must be relative to the symlink file itself, not to the location where you run the ln -s
command. To make sure you don't get that wrong (and because you get convenient tab completion with it), there are two options:
Either go to the symlink's directory first, and create the symlink there:
$ cd platform-tools
$ ln -s ../build-tools/20.0.0/lib lib # The last lib is optional
Or use the -r
option to make ln
figure out the relative path while you specify paths relative to your current directory:
$ ln -sr build-tools/20.0.0/lib platform-tools/lib
ls -la platform-tools/lib | grep "^l"
?