2

Out of curiosity i wanted to open a symlink as itself instead of the file it points to, just to see how it looks like. While there are ways to see what file it points to like using readlink and ways to copy symlinks themselves like cp -P, none of these allow you to see the actual contents of the symlink.

Is there a simple way to accomplish this? (either in plain text or in hexadecimal)

  • 1
    Related - [How does one view what the contents of symbolic link are, instead of the destination?](https://unix.stackexchange.com/q/83017/100397) and [Actual content of a symlink file](https://unix.stackexchange.com/q/609474/100397) and maybe possibly [is there a way to see the actual contents of a symlink?](https://stackoverflow.com/q/4572805/2344631). None is a strict duplicate – roaima Aug 16 '21 at 20:54
  • 1
    What? `readlink` reads the actual contents of the symlink. A symlink doesn't necessarily point to a file; it can be dangling. `readlink` will read whatever is in it. – Kaz Aug 24 '21 at 23:24

1 Answers1

4

Symlinks don't have any other content beside the link target, which you'd read with readlink().

As for symlink's metainfo. check lstat().

lstat() is identical to stat(), except that if pathname is a symbolic link, then it returns information about the link itself, not the file that it refers to.

ilkkachu
  • 133,243
  • 15
  • 236
  • 397
Kevin Chan
  • 56
  • 4