Jar*_*red 143 linux command-line-interface symbolic-link
假设我设置了一个符号链接:
ln -s /root/Public/mytextfile.txt /root/Public/myothertextfile.txt
Run Code Online (Sandbox Code Playgroud)
有没有办法myothertextfile.txt使用命令行查看目标是什么?
bri*_*zil 187
使用该-f标志打印规范化版本。例如:
readlink -f /root/Public/myothertextfile.txt
Run Code Online (Sandbox Code Playgroud)
来自man readlink:
-f, --canonicalize
canonicalize by following every symlink in every component of the given name recursively; all but the last component must exist
Run Code Online (Sandbox Code Playgroud)
Kyl*_*ndt 24
readlink 是您想要的命令。您应该查看该命令的手册页。因为如果你想跟随一系列符号链接到实际文件,那么你需要 -e 或 -f 开关:
$ ln -s foooooo zipzip # fooooo doesn't actually exist
$ ln -s zipzip zapzap
$ # Follows it, but doesn't let you know the file doesn't actually exist
$ readlink -f zapzap
/home/kbrandt/scrap/foooooo
$ # Follows it, but file not there
$ readlink -e zapzap
$ # Follows it, but just to the next symlink
$ readlink zapzap
zipzip
Run Code Online (Sandbox Code Playgroud)
这也将起作用:
ls -l /root/Public/myothertextfile.txt
Run Code Online (Sandbox Code Playgroud)
但readlink更适合在脚本中使用而不是解析ls.
如果要显示链接的来源和目的地,请尝试stat -c%N files*。例如
$ stat -c%N /dev/fd/*
‘/dev/fd/0’ -> ‘/dev/pts/4’
‘/dev/fd/1’ -> ‘/dev/pts/4’
Run Code Online (Sandbox Code Playgroud)
它不利于解析(用于解析readlink),但它显示链接名称和目的地,没有混乱ls -l
-c可以写成--format,%N意思是“引用的文件名,如果是符号链接,则取消引用”。
| 归档时间: |
|
| 查看次数: |
232758 次 |
| 最近记录: |