19 linux shell path command-line
我们有两条路。第一个是目录,第二个是目录或文件。
/a/b/c 和 /a/d/e.txt
从第一条路径到第二条路径的相对路径为:
../../d/e.txt
如何在 Linux 终端中计算它?对于那些问“什么是用例?”的人 例如,可以使用它来创建大量相对符号链接。
use*_*686 10
假设 GNU coreutils:
对于符号链接,ln最近学习了该--relative选项。
对于其他一切,realpath支持选项--relative-to=和--relative-base=.
小智 5
对我来说,这个答案(使用 python oneliner)很完美。
$ python -c "import os.path; print os.path.relpath('/a/d/e.txt', '/a/b/c')"
../../d/e.txt
Run Code Online (Sandbox Code Playgroud)
在 linux (Kubuntu 14.04) 和 Mac OSX 上测试成功,需要 Python 2.6。
| 归档时间: |
|
| 查看次数: |
22761 次 |
| 最近记录: |