Posted By

deepsoul on 08/15/09


Tagged

path link unix linux directory hard symbolic


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

riddla


Creating links in different directories (Linux/UNIX)


 / Published in: Bash
 

When using ln to create a link in a different directory, the semantics of creating hard and symbolic links differ. That is because a hard link contains a direct reference to its target's data, while a symbolic link is just a string containing a (possibly relative) path. You can get around this by using absoute paths, but then moving a subtree will break the symlink.

Just to recap, the other main differences between hard and symbolic links: Symbolic links can be left dangling when their target is removed; hard links cannot. Symbolic links can point to files on other partitions or disks, while hard links cannot.

  1. # create hard link in subdir which points to ../otherdir/file
  2. ln ../otherdir/file subdir/link
  3.  
  4. # create symbolic link in subdir which points to ../otherdir/file
  5. ln -s ../../otherdir/file subdir/symlink
  6. # note the additional "../" which compensates the subdir

Report this snippet  

You need to login to post a comment.