Symlink generates empty alias file?
Asked Answered
S

2

6

I'm trying to create a folder that is going to contain all files that are in another folder.

This is the tree structure. I want to symlink source to target.

.
├── source-folder
    └── source <-- source folder
└── controllers
    └── another-folder
        └── yet-another-folder
            └── target <-- target folder

I tried

ln -s source-folder/source controllers/another-folder/yet-another-folder/target

but it only creates an empty alias file.

How do I create a folder that contains the same data that is in the source-folder/source folder?

Sarre answered 25/3, 2014 at 10:54 Comment(1)
You need to specify a full path for the source folder not a relative one.Bicameral
S
6

I solved it by placing myself in yet-another-folder and doing;

ln -s ../../../source-folder/source target

So I'm placed in the target's parent folder and the specified source path is relative to where I'm placed.

Sarre answered 25/3, 2014 at 14:42 Comment(3)
Don't you need another level of .. there? You need to go up 3 levels before you can come down to source-folder.Apothecium
@Apothecium You are correct. My example tree wasn't the same as my real tree so that's why :).Sarre
Is a great workaround, I did ln -s node_modules node_modules2 and then mv node_modules2 public`. It worked well but the answer from @Postorbital bellow seems to be more technically accurated.Wappes
P
13

Better to create symlinks with full paths; it then works as expected

Postorbital answered 11/10, 2014 at 22:59 Comment(1)
technically not required, BUT chances are you'll lose more time figuring out a wrong relative path - compared to the amount of time typing a full path. generally speaking, using full path rather than relative path is more robust (IMHO)Postorbital
S
6

I solved it by placing myself in yet-another-folder and doing;

ln -s ../../../source-folder/source target

So I'm placed in the target's parent folder and the specified source path is relative to where I'm placed.

Sarre answered 25/3, 2014 at 14:42 Comment(3)
Don't you need another level of .. there? You need to go up 3 levels before you can come down to source-folder.Apothecium
@Apothecium You are correct. My example tree wasn't the same as my real tree so that's why :).Sarre
Is a great workaround, I did ln -s node_modules node_modules2 and then mv node_modules2 public`. It worked well but the answer from @Postorbital bellow seems to be more technically accurated.Wappes

© 2022 - 2024 — McMap. All rights reserved.