如何使用 `stat` 通过符号 link 获取最终点的路径

How to get the path of the final final point by a symbolic link using `stat`

我尝试获取符号指向的文件夹/文件的名称link。

例如,当您 ls -l 你可以得到这个结果

-rw-r--r--  1 macos  staff  0 Feb 22 12:05 test
lrwxr-xr-x  1 macos  staff  7 Feb 19 11:05 sl -> test

如果我知道 sl 的路径以获取它指向的 file/folder,我该怎么做?

如果可能的话,我想使用 stat 来完成。

有什么建议吗?

总结一下:

使用lstatstat.

无法获得符号link指向的file/folder的名称

函数 readlink 可以完成这项工作 => Man : http://man7.org/linux/man-pages/man2/readlink.2.html。你会在 man

中得到例子

谢谢你帮我解决问题