有没有办法查看符号链接的实际内容?
当您这样做时
cat some-symlink-to-some-real-file
,它会显示真实文件的内容,而不是符号链接本身的内容。有没有办法看到里面到底有什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
ls -l
命令将向您显示:或者
readlink
命令:因此,符号链接
foo
指向路径/etc/passwd
。The
ls -l
command will show you that:Or the
readlink
command:So, the symbolic link
foo
points to the path/etc/passwd
.您可以调用
readlink(2)
函数,该函数将将链接到的名称放入缓冲区中。请注意,结果具有长度(存储在返回值中)而不是以 NUL 结尾。因此,如果您想将其用作字符串,请自己附加一个 NUL。
大多数高级/脚本语言,例如 perl 或 python,将提供一个 readlink 包装器,该包装器可以转换为通常的语言适当的字符串类型,因此您不会被诸如 NUL 终止之类的细节所困扰。
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.
关于手册页 http://man7.org/linux/man-pages /man7/symlink.7.html 符号链接是常规文件(带有特殊标志),其内容包含目标路径。因此,您可以将符号链接复制到 FAT 分区并读取其中的内容。
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
请参阅下面的
ls -l
结果。每个链接的大小正是存储原始文件名称所需的字节数。正如 @BenVoigt 提到的,甚至没有最终的 NUL。当然它不是文件的绝对路径。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.