如何获得符号链接的目标? [英] How do I get the target of a symlink?
本文介绍了如何获得符号链接的目标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个字符串,其中包含现有符号链接的文件系统路径.我想得到这个链接指向的路径.
I have a string containing the file system path to an existing symlink. I want to get the path that this link points to.
基本上我想要的东西和我能通过这点黑客一样:
Basically I want the same that I'd get through this bit of hackery:
s = "path/to/existing/symlink"
`ls -ld #{s}`.scan(/-> (.+)/).flatten.last
但我想在不花钱的情况下做到这一点.
but I want to do it without shelling out.
推荐答案
我认为 readlink 就是您要查找的内容:
I think readlink is what you are looking for:
File.readlink("path/to/symlink")
这篇关于如何获得符号链接的目标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文