Follow us on...
Follow us on Twitter Follow us on Facebook
Register
Results 1 to 7 of 7
  1. #1
    kainjow is offline Registered User
    Join Date
    Nov 2000
    Posts
    949
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Relative Symbolic Link

    Is it possible to create a symlink that uses a relative path instead of an absolute one?

  2. #2
    lurk's Avatar
    lurk is offline Mitä?
    Join Date
    Mar 2002
    Location
    Land o' skeeterz
    Posts
    2,087
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yep just use .. like "../../mygrandpa/uncle/cuosin.txt"

  3. #3
    kainjow is offline Registered User
    Join Date
    Nov 2000
    Posts
    949
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sweet it works, thanks.

    I could have swore I tried that though.. oh well

  4. #4
    kainjow is offline Registered User
    Join Date
    Nov 2000
    Posts
    949
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Annoyingly Panther doesn't have the "readlink" command like Tiger, but "file" can read symlinks though

  5. #5
    leonpmu is offline Registered User
    Join Date
    Feb 2005
    Location
    Mauritius
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    did you try "ln -l" which makes a "soft" symlink...

  6. #6
    not-just-yeti is offline Registered User
    Join Date
    Aug 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If you symlink to an *existing* file, the symlink is changed to an absolute path.
    However, if you symlink to a *non*existing file (or, a to file whose pathname contains a symlink), then you get a relative link:

    cd
    mkdir Tmp1
    mkdir Tmp2
    touch Tmp1/file1
    cd Tmp2
    ln -s ../Tmp1/file1 f1
    ln -s ../Tmp1/file2 f2
    ls -l
    # f1 @ -> /Users/yeti/Tmp1/file1
    # f2 @ -> ../Tmp1/file2

    You can then create Tmp1/file2, and Tmp2/f2 will be a relative link to it.


    [Hmm, my characterization isn't *quite* complete, since `cd ; ln -s Tmp1/file1 f1` also creates a relative symlink, even though `Tmp/f1` exists.]


    I don't know why `ln` doesn't just have a switch to force an absolute-path, with relative paths being the default.

    [This is all confirmed on 10.8 Mountain Lion, but I suspect it's been like this for a while.]

  7. #7
    not-just-yeti is offline Registered User
    Join Date
    Aug 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    first make the link, *then* make the destination file

    If you symlink to an *existing* file, the symlink is changed to an absolute path.
    However, if you symlink to a *non*existing file (or, a to file whose pathname contains a symlink), then you get a relative link:

    cd
    mkdir Tmp1
    mkdir Tmp2
    touch Tmp1/file1
    cd Tmp2
    ln -s ../Tmp1/file1 f1
    # linking to a file that doesn't yet exist:
    ln -s ../Tmp1/file2 f2
    ls -l
    # f1 @ -> /Users/yeti/Tmp1/file1
    # f2 @ -> ../Tmp1/file2

    You can then create Tmp1/file2, and Tmp2/f2 will (still) be a relative link to it.


    [Hmm, my characterization isn't *quite* complete, since `cd ; ln -s Tmp1/file1 f1` also creates a relative symlink, even though `Tmp/f1` exists.]


    I don't know why `ln` doesn't just have a switch to force an absolute-path, with relative paths being the default.

    [This is all confirmed on 10.8 Mountain Lion, but I suspect it's been like this for a while.]

 

 

Similar Threads

  1. HIToolbox symbolic link problem
    By Roos in forum Unix & X11
    Replies: 0
    Last Post: January 8th, 2006, 06:30 PM
  2. Symbolic Link Problem.
    By Ramkisaur_Prajapat in forum Mac OS X System & Mac Software
    Replies: 3
    Last Post: August 26th, 2005, 11:29 PM
  3. Dreamweaver : Alias & Symbolic Link Help Needed
    By addhass in forum Mac OS X System & Mac Software
    Replies: 3
    Last Post: July 7th, 2005, 02:50 PM
  4. Alias and Symbolic link
    By Not a Duck in forum Mac OS X System & Mac Software
    Replies: 1
    Last Post: June 29th, 2002, 12:46 PM
  5. Symbolic link and CDROM
    By byronw70 in forum Mac OS X System & Mac Software
    Replies: 3
    Last Post: July 31st, 2001, 09:37 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •