我对软链接(soft link)在 unix 中的工作方式有些困惑。请参阅示例。
% cd /usr/local/
% ls -la
total 6
drwxr-xr-x 2 root root 512 Jan 19 15:03 .
drwxr-xr-x 41 root sys 1024 Jan 20 16:24 ..
lrwxrwxrwx 1 root root 38 Jan 19 15:03 java -> /otherDir/java/jdk1.6.0_17 **<- this is a soft link**
% cd java **<- move to the softlink**
% pwd
/usr/local/java **<- the current location, say LOCATION_A**
% cd /otherDir/java/jdk1.6.0_17/ **<-move to the location of the softlink**
% pwd
/otherDir/java/jdk1.6.0_17 **<- the new current location, say LOCATION_B**
即使 LOCATION_A 是 LOCATION_B,他们有不同的路径,这不是有问题吗?
是否有一个命令(pwd 除外)可以给出文件的真实位置(而不仅仅是用户如何到达那里)。
在我看来,pwd 只是用户 cd 的总和。不是他们当前的位置。
最佳答案
试试 pwd -P
。它不是“除了 pwd”,但它可以解决问题,至少在我的 Fedora 12 上的 bash 4.0.35 上是这样。YMMV。
更新:甚至可以与 sh
一起使用,所以它似乎是可移植的。
关于Unix 软链接(soft link)和路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2105572/