简体   繁体   English

有没有办法看到符号链接的实际内容?

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

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命令将显示:

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

Or the readlink command : readlink命令

$ readlink foo
/etc/passwd

So, the symbolic link foo points to the path /etc/passwd . 因此,符号链接foo指向路径/etc/passwd

You can call the readlink(2) function, which will place the linked-to name into a buffer. 您可以调用readlink(2)函数,该函数将链接到的名称放入缓冲区。

Note that the result has a length (stored in the return value) rather than being NUL-terminated. 请注意,结果具有长度(存储在返回值中)而不是NUL终止。 So if you want to use it as a string, append a NUL yourself. 因此,如果您想将其用作字符串,请自行附加NUL。

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. 大多数高级/脚本语言(如perl或python)将提供一个readlink包装器,它将转换为通常的语言相应的字符串类型,因此您不会受到诸如NUL终止等细节的困扰。

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. 关于手册页http://man7.org/linux/man-pages/man7/symlink.7.html symlink是常规文件(带有特殊标志),其内容中包含目标路径。 So you could copy symlink to FAT partition and read it content there. 所以你可以将符号链接复制到FAT分区并在那里读取内容。

尝试

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM