Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Create the following directories:


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?

share|improve this question
up vote 3 down vote accepted

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
share|improve this answer
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 Jun 27 '11 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 Jun 27 '11 at 19:31
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 Jun 27 '11 at 19:34

You must log in to answer this question.

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