什么是路径//,它与/有什么不同?

时间:2013-05-30 16:05:04

标签: linux kernel posix pathname

我们知道根目录是/,并且根据posix,还有另一个目录//与/不同。当你ls /和ls //时,输出是相同的,所以作为stat,但是如果你cd /和cd //,它们是不同的,虽然目录内容是相同的。 这让我很困惑。有人得到了答案吗?

1 个答案:

答案 0 :(得分:20)

来自Bash FAQ

E10) Why does `cd //' leave $PWD as `//'?

POSIX.2, in its description of `cd', says that *three* or more leading
slashes may be replaced with a single slash when canonicalizing the
current working directory.

This is, I presume, for historical compatibility.  Certain versions of
Unix, and early network file systems, used paths of the form
//hostname/path to access `path' on server `hostname'.