1

Is there some way in which I can view/edit what the contents of a symbolic link are? I don't want to view the destination the link points to, but the symbolic link itself.

Suppose I have a file, file.txt and I create a link to file.txt as

    ln -s $HOME/path/to/file.txt .

Now, if I copy this link to a different system, this link will point to nothing if $HOME expands to something different on the other system, even if the path after $HOME is still the same. Is there some way to edit the link file so that $HOME is not expanded before creating the file, but is a part of the file itself?

user1544430
  • 11
  • 1
  • 2
  • Symbolic links don't store variable names. Your shell is expanding the variable before it gets to the `ln` executable. If you tried to copy it, `cp` would follow the link and copy the target. You can merely instruct `cp` to copy the link if that's what you want too. – Bratchley Jul 14 '13 at 22:06
  • @Gilles: Dynamic Symlinks are what I need! Thanks very much. – user1544430 Jul 14 '13 at 23:24

1 Answers1

1

readlink will show you the content of the link, but the destination is all there is.

You can't put variables in a symbolic link, but you can make the paths relative. So if you have:

$HOME/path/to/file.txt
$HOME/other/path/to/symlink.txt

You could create the symlink as ../../../path/to/file.txt, it will point to file.txt regardless of what $HOME is.

ln -s ../../../path/to/file.txt $HOME/other/path/to/symlink.txt
David Baggerman
  • 2,154
  • 20
  • 11