Linux 如何查看完整的符号链接路径

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16017500/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 22:43:02  来源:igfitidea点击:

How to see full symlink path

linux

提问by 15412s

When I'm using ls -la symlinkNameor stat symlinkNamenot all the path is displayed (e.g ../../../one/two/file.txt)

当我使用ls -la symlinkNamestat symlinkName不显示所有路径时(例如../../../one/two/file.txt

What is the linux command that reveals the full path?

显示完整路径的linux命令是什么?

采纳答案by Ian Stapleton Cordasco

realpathisn't available on all linux flavors, but readlinkshould be.

realpath并非在所有 linux 版本上都可用,但readlink应该可用。

readlink -f symlinkName

The above should do the trick.

以上应该可以解决问题。

Alternatively, if you don't have either of the above installed, you can do the following if you have python 2.6 (or later) installed

或者,如果您没有安装上述任何一个,如果您安装了 python 2.6(或更高版本),则可以执行以下操作

python -c 'import os.path; print(os.path.realpath("symlinkName"))'

回答by JosephH

realpath <path to the symlink file>should do the trick.

realpath <path to the symlink file>应该做的伎俩。

回答by Rupam

unix flavors -> ll symLinkName

Unix 口味 -> ll symLinkName

OSX -> readlink symLinkName

OSX -> readlink symLinkName

Difference is 1st way would display the sym link path in a blinking way and 2nd way would just echo it out on the console.

不同之处在于第一种方式会以闪烁的方式显示符号链接路径,第二种方式只会在控制台上回显出来。

回答by user3467349

You can use awkwith a systemcall readlinkto get the equivalent of an lsoutput with full symlink paths. For example:

您可以使用awkwithsystem调用readlink来获得ls具有完整符号链接路径的输出。例如:

ls | awk '{printf("%s ->", ); system("readlink -f " )}'

Will display e.g.

将显示例如

thin_repair ->/home/user/workspace/boot/usr/bin/pdata_tools
thin_restore ->/home/user/workspace/boot/usr/bin/pdata_tools
thin_rmap ->/home/user/workspace/boot/usr/bin/pdata_tools
thin_trim ->/home/user/workspace/boot/usr/bin/pdata_tools
touch ->/home/user/workspace/boot/usr/bin/busybox
true ->/home/user/workspace/boot/usr/bin/busybox

回答by Engr. Hasanuzzaman Sumon

Another way to see information is statcommand that will show more information. Command stat ~/.sshon my machine display

查看信息的另一种方法是stat显示更多信息的命令。stat ~/.ssh我机器上的命令显示

File: ‘/home/sumon/.ssh' -> ‘/home/sumon/ssh-keys/.ssh.personal'
  Size: 34          Blocks: 0          IO Block: 4096   symbolic link
Device: 801h/2049d  Inode: 25297409    Links: 1
Access: (0777/lrwxrwxrwx)  Uid: ( 1000/   sumon)   Gid: ( 1000/   sumon)
Access: 2017-09-26 16:41:18.985423932 +0600
Modify: 2017-09-25 15:48:07.880104043 +0600
Change: 2017-09-25 15:48:07.880104043 +0600
 Birth: -

Hope this may help someone.

希望这可以帮助某人。