Linux获取两个路径之间的相对路径
获取两个路径之间的相对路径是一个很常见的问题,在Linux中怎么实现呢?
为了进行隔离,整个项目是用chroot跑的,有一次为了在chroot下建一个软链接,又不能用绝对路径,想自动计算一个路径相对于另一个路径的相对路径,怎么办呢?
经过一番搜索后发现,Linux中realpath和ln都有这个功能。
- realpath
realpath [OPTION]... FILE... --relative-to=FILE print the resolved path relative to FILE
example:
# realpath /var/chroot/var/log --relative-to=/var/chroot/var/lib/data/log ../../../log
- ln
ln [OPTION]... [-T] TARGET LINK_NAME -r, --relative create symbolic links relative to link location
example:
# ln -sr /var/chroot/var/log /var/chroot/var/lib/data/log/mylog # ll /var/chroot/var/lib/data/log/ total 0 lrwxrwxrwx 1 root root 12 Mar 3 09:21 mylog -> ../../../log
相关推荐
Bonrui编程路 2020-07-18
深井兮兮 2020-07-18
Alisa0 2020-06-14
DBATips 2020-06-07
atb 2020-04-18
taoqidejingling 2020-03-05
sunln00 2020-02-20
林大夏 2020-02-16
aihenaichadeyun 2019-12-20
csdnyasin 2019-12-21
福叔 2019-12-09
gaozhlzh 2013-09-11
心动 2019-11-17
lyccsu 2015-05-15
lhxxhl 2019-06-10
snowknow 2019-07-01
lovexiaoqiqi 2019-05-20
Dongxiem 2015-09-08
89550492 2011-06-06