is there a way to see the actual contents of a symlink?

39,242

Solution 1

The ls -l command will show you that:

$ ls -l foo
lrwxrwxrwx 1 user group 11 2010-12-31 19:49 foo -> /etc/passwd

Or the readlink command:

$ readlink foo
/etc/passwd

So, the symbolic link foo points to the path /etc/passwd.

Solution 2

You can call the readlink(2) function, which will place the linked-to name into a buffer.

Note that the result has a length (stored in the return value) rather than being NUL-terminated. So if you want to use it as a string, append a NUL yourself.

Most higher-level/scripting languages, such as perl or python, will provide a readlink wrapper that converts to the usual language-appropriate string type, so you won't be bothered by details such as NUL-termination.

Solution 3

Regarding to man page http://man7.org/linux/man-pages/man7/symlink.7.html symlink is regular file (with special flag) with path to target in its content. So you could copy symlink to FAT partition and read it content there.

Solution 4

Try

find . -type l -exec ls -la {} \;
Share:
39,242
fabio
Author by

fabio

Updated on July 08, 2022

Comments

  • fabio
    fabio almost 2 years

    When you do

    cat some-symlink-to-some-real-file
    

    it shows the contents of the real file, not what is within the symlink itself. Is there a way to see what's actually in it?