How to create relative symbolic link in mac OS? [closed]
Asked Answered
D

2

29

How to create a relative symbolic link that would always point to original folder two levels up? I would like to create a computer-independent alias that would work on any machine, provided that the original folder exists two levels up.

Basically, what I want is this:

  |-- Original    
  |-- folder 1    
    |-- folder 2
      |-- Original alias   

I need this for my XCode project structure. I've tried:

ln -s Original /../../Original

but it creates an alias that cannot find its original folder.

Dug answered 1/5, 2013 at 12:6 Comment(1)
Why not move this to Super User?Diego
G
44

I think, you have the order of the arguments backwards. It should be:

$ ln -s <dest> <link>

Where <dest> becomes the contents of the new link created.

In your specific example:

$ cd "folder 1"/"folder 2"
$ ln -s ../../Original Original

Or, in one command, from base directory:

$ ln -s Original "folder 1/folder 2/Original"
Graphophone answered 1/5, 2013 at 15:26 Comment(5)
also, note that you must enclose "<dest>" in quotes, because otherwise bash will auto-expand it to an absolute path, and you'll end up creating an absolute symlink, not a relative oneSanitarium
@AlJey The only way I can think of that bash would do that is if <dest> started with ~. I've never seen it take something like ../../Original and convert that into an absolute path.Graphophone
@Graphophone Well, on my system (10.11.6) this happens every time. This was, in fact, always the case for me even on older versions. Not only in OS X, but in Ubuntu as well. Bash generally tries to auto-expand paths, always.Sanitarium
@twalberg, Are you sure? It prints link source_file target_file for me.Orthochromatic
@IulianOnofrei Yes - just a difference in terminology. <link> in my answer, and target_file from the usage message are the thing that gets created, referencing <dest> or source_file, respectively.Graphophone
D
3

take out the first / - thats an absolute link from root, you want ../../ to be relative from current location.

Difficulty answered 1/5, 2013 at 12:13 Comment(1)
still, no luck. Finder cannot find original folderDug

© 2022 - 2024 — McMap. All rights reserved.