![如何通过动态文件链接到达其主目录?](https://linux22.com/image/520628/%E5%A6%82%E4%BD%95%E9%80%9A%E8%BF%87%E5%8A%A8%E6%80%81%E6%96%87%E4%BB%B6%E9%93%BE%E6%8E%A5%E5%88%B0%E8%BE%BE%E5%85%B6%E4%B8%BB%E7%9B%AE%E5%BD%95%EF%BC%9F.png)
>ls -alt
lrwxrwxrwx 1 root root 67 Aug 3 10:49 myFile.txt -> /some/where/else/myFile.txt
我想 cd 到
/some/where/else/
通过输入类似
follow myFile.txt
Unix 有类似的东西吗?
答案1
你可以定义一个函数:
follow () { cd $(dirname $(readlink -e "$1")); }
>ls -alt
lrwxrwxrwx 1 root root 67 Aug 3 10:49 myFile.txt -> /some/where/else/myFile.txt
我想 cd 到
/some/where/else/
通过输入类似
follow myFile.txt
Unix 有类似的东西吗?
你可以定义一个函数:
follow () { cd $(dirname $(readlink -e "$1")); }