5

I have a directory to which I want to create a symbolic link. The commands I used were:

cd workspace_b4a
cd android-sdk-linux
ln -sv build-tools/20.0.0/lib/ platform-tools/lib

The output was:

‘platform-tools/lib’ -> ‘build-tools/20.0.0/lib/’

However, Nautilus says that platform-tools/lib is a broken link and ls -l platform-tools/lib shows the both build-tools/20.0.0/lib/ and platform-tools/lib in red. What am I doing wrong?

2
  • what is the output of ls -la platform-tools/lib | grep "^l"? Sep 16, 2014 at 8:16
  • Take a look at this.
    – Mitch
    Sep 16, 2014 at 8:17

4 Answers 4

4

Thanks everyone for your suggestions. I found it easiest to understand how to do it (though I still don't understand the logic behind it) with:

cd ~/workspace_b4a
cd android-sdk-linux
cd platform-tools
ln -sv ../build-tools/20.0.0/lib/ .
3

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
2

You can link to a non existing PATH (either file or directory)

abox $ ls
abox $ ln -s foo bar
abox $ ls
bar  (<- in red)
abox $ ls -l
total 0
lrwxrwxrwx 1 archemar archemar 3 sept. 16 10:47 bar -> foo  ## both foo and bar in red

Why someone would do that ?

Latter, i can create foo file/dir, and link will work.

while directory build-tools/20.0.0/lib/ does not exsists, your link will be broken.

0

I'd assume that you are in a directory

/media/john/android/workspace_b4a/android-sdk-linux/

and you want to create a symbolic link for '/build-tools/20.0.0/lib' dir it. You can do that by

     ln -sv /media/john/android/workspace_b4a/android-sdk/build-tools/20.0.0/lib platform-tools/lib

EDIT : The output of

   ls -l platform-tools/lib

Will also be changed.

2
  • 1
    you can link with relative pathname.
    – Archemar
    Sep 16, 2014 at 8:46
  • My apologies for misguidance. Sep 16, 2014 at 9:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .