我有点困惑的链接如何在软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的简单相加。不是他们的当前位置。

有帮助吗?

解决方案

此行为类似于此同一个目的。如果你cd到/a/b/c/d然后cd到..那么你现实期望在/a/b/c。如果c恰好是一个符号链接(或UNIX术语符号链接 - 但不是软链接),您可以到/f/g/h,与行为,你想有你在/f/g结束了,然后你(或程序)将不了解它是如何到达那里。

其他提示

尝试pwd -P。这不是“比其他PWD”,但它的伎俩,至少在我在Fedora 12因人而异的bash 4.0.35。

更新:即使作品与sh,所以它似乎是便携

您可以使用的readlink当前工作目录,以获得真正的目录名称:

readlink `pwd`

一般情况下,应pwd在最后一行返回/usr/local/java,如果我理解你的榜样。但是,一些炮弹有一个的建立pwd命令,试图更加“智能”处理符号链接的当前工作目录。

尝试/bin/pwd,你得到其他结果?

真实路径做什么你想。

这是不可能获得绝对在任何情况下你的路径。这是有点奇怪,但这个(加的chroot和setuid的)的变化有时用于锁定下一个过程。

$ mkdir -p /tmp/a/b
$ cd /tmp/a/b
$ rmdir /tmp/a/b
$ chmod 0 /tmp/a
$ rmdir /tmp/a
$ ls ..
ls: cannot open directory ..: Permission denied
$ ls -al
total 0
$ pwd -P
pwd: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top