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

LinuxShellFilesystemsSymlinkCat

Linux Problem Overview


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?

Linux Solutions


Solution 1 - Linux

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 - Linux

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 - Linux

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 - Linux

Try

find . -type l -exec ls -la {} \;

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionfabioView Question on Stackoverflow
Solution 1 - LinuxPleaseStandView Answer on Stackoverflow
Solution 2 - LinuxBen VoigtView Answer on Stackoverflow
Solution 3 - LinuxPavel PatrinView Answer on Stackoverflow
Solution 4 - LinuxEric FortisView Answer on Stackoverflow