1

Create the following directories:

parent/child

Navigate to child and create a file named child (this is an executable file in my case, not sure if that makes a difference).

I need to create two "link to executable" links in the parent. I had assumed that this would work:

ln -sf ./child ../child1
ln -sf ./child ../child2

But that creates a "link to folder" (./child) in the parent directory.

If I change it to:

ln -sf -t.. ./child child1
ln -sf -t.. ./child child2

I get an error, "ln: '../child': cannot overwrite directory".

If I do it from the parent directory (which I cannot do, this is part of a Makefile recipe):

ln -sf ./child/child ./child1
ln -sf ./child/child ./child2

It works.

Note that I cannot alter the names of any directories or files.

How do I create the links when the current directory is the child?

1 Answer 1

5

That's because the first argument, TARGET, is relative to the location of the link. In other words, you're creating links called parent/child1 and parent/child2 which both link to ./child. From the perspective of those links, ./child is the directory. You need to link to ./child/child. Or better yet, create an absolute link:

ln -sf /full/path/to/parent/child/child ../child1
ln -sf /full/path/to/parent/child/child ../child2
3
  • But that would require hard-coding the full/path/to/parent in the Makefile. I just tried ln -sf ../child/child ../child1 which produced a broken link. Is there no way to do it without the full path?
    – Tergiver
    Commented Jun 27, 2011 at 19:30
  • Use ./child/child as I suggested, rather than ../child/child, as you said you did. But using full paths in a Makefile should be easy anyway. I do it all the time in my own Makefiles.
    – Flimzy
    Commented Jun 27, 2011 at 19:31
  • 1
    You're right, I had access to a $(ROOTDIR) variable which allowed me to do it with the full path and not a hard-coded path. Thank you.
    – Tergiver
    Commented Jun 27, 2011 at 19:34

You must log in to answer this question.

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