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?
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?
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
.
ls
and readlink
are both separate applications. –
Swath stat
or ls -di
. –
Fascia 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.
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.
Try
find . -type l -exec ls -la {} \;
See result of ls -l
below. Size of each link is exactly how many bytes is needed for storing name of the original file. Not even final NUL is there, as @BenVoigt mentions. And surely it is not the absolute path of the file.
© 2022 - 2024 — McMap. All rights reserved.
readlink(2)
. As noted in one of the answers, the direct command to use isreadlink(1)
on some systems (GNU and relatives). On other systems - HP-UX, Solaris, AIX - the closest approach is likely to bels -l
, but be aware of problems if the path name in the link contains newlines or other weird characters. – Penland