realpath和readlink命令

-- TOC --

realpath命令可用于解析某个相对路径的完整路径,readlink专用于symbolic link的路径解析。

realpath

realpath - print the resolved path

[root@localhost origin]# realpath .
/opt/2104/origin
[root@localhost origin]# realpath ~
/root
[root@localhost origin]# realpath output/*
/opt/2104/origin/output/dist
/opt/2104/origin/output/doc
/opt/2104/origin/output/linux
/opt/2104/origin/output/misc
/opt/2104/origin/output/origin
/opt/2104/origin/output/preboot
/opt/2104/origin/output/server
/opt/2104/origin/output/win32

获取symbolic link的最终指向:

[root@localhost origin]# realpath /usr/bin/xzcat
/usr/bin/xz
[root@localhost origin]# realpath /usr/bin/vimdiff
/usr/bin/vim

readlink - print resolved symbolic links or canonical file names

$ readlink /usr/bin/awk  
/etc/alternatives/awk  ----> 其实这个还是一个符号连接  
$ readlink /etc/alternatives/awk  
/usr/bin/gawk  ----> 这个才是真正的可执行文件
$ readlink -f /usr/bin/awk
gawk

-f

本文链接:https://cs.pynote.net/sf/linux/shell/202111024/

-- EOF --

-- MORE --