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

dsp*_*pjm 13 linux posix kernel pathname

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

dev*_*ull 21

来自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'.
Run Code Online (Sandbox Code Playgroud)

  • 在我的 git bash 仿真(技术上是一台 Windows 机器)上,尝试 `ls -l //` 会导致机器尝试读取并列出整个可用网络......哇。 (3认同)