当前位置: 技术问答>linux和unix
linux 根目录(/)(//) 区别
来源: 互联网 发布时间:2017-03-18
本文导语: [freeubun@m-net ~]$ pwd /home/guest/freeubun [freeubun@m-net ~]$ cd / [freeubun@m-net /]$ pwd / [freeubun@m-net /]$ ls COPYRIGHT entropy m rescue tmp arbornet etc ...
[freeubun@m-net ~]$ pwd
/home/guest/freeubun
[freeubun@m-net ~]$ cd /
[freeubun@m-net /]$ pwd
/
[freeubun@m-net /]$ ls
COPYRIGHT entropy m rescue tmp
arbornet etc media root u
bin g mnt s usr
boot home newhome sbin var
cdrom lib p suid
dev libexec proc sys
[freeubun@m-net /]$ cd //
[freeubun@m-net //]$ pwd
//
[freeubun@m-net //]$ ls
COPYRIGHT entropy m rescue tmp
arbornet etc media root u
bin g mnt s usr
boot home newhome sbin var
cdrom lib p suid
dev libexec proc sys
[freeubun@m-net //]$
能否告知(cd /)与(cd //)的区别
/home/guest/freeubun
[freeubun@m-net ~]$ cd /
[freeubun@m-net /]$ pwd
/
[freeubun@m-net /]$ ls
COPYRIGHT entropy m rescue tmp
arbornet etc media root u
bin g mnt s usr
boot home newhome sbin var
cdrom lib p suid
dev libexec proc sys
[freeubun@m-net /]$ cd //
[freeubun@m-net //]$ pwd
//
[freeubun@m-net //]$ ls
COPYRIGHT entropy m rescue tmp
arbornet etc media root u
bin g mnt s usr
boot home newhome sbin var
cdrom lib p suid
dev libexec proc sys
[freeubun@m-net //]$
能否告知(cd /)与(cd //)的区别
|
It's explained in POSIX, "4.11 Pathname resolution".
"A pathname consisting of a single slash shall resolve to the root directory
of the process. A null pathname shall not be successfully resolved. A
pathname that begins with two successive slashes may be interpreted in an
implementation-defined manner, although more than two leading slashes shall
be treated as a single slash."
IIRC, the special treatment ("implementation-defined manner") of pathnames
that begin with two successive slashes is there to recognize a historical
remnant of some Unix system's attempts at rationalizing a "network file
system" into the standard Unix pathname conventions.
If a path started with _one_ slash, it was deemed to name a path on the
local file system. So
/usr/lib
could be found on the currently mounted filesystem tree.
However, if the path started with _two_ slashes, then the first component
was deemed to be a hostname for a network filesystem, and the remaining
path was relative to that host's exported filesystem. So
//LibraryOfCongress/data/cardcatalog/A-D/A101101101
could be found on the server named "LibraryOfCongress".
POSIX and the SUS are attempts to rationalize the behaviours of many
propriatary Unix systems into a single standard, and sometimes carry
caveats to cover where unique Unix systems have deviated from the norm.
This is one such case.
"A pathname consisting of a single slash shall resolve to the root directory
of the process. A null pathname shall not be successfully resolved. A
pathname that begins with two successive slashes may be interpreted in an
implementation-defined manner, although more than two leading slashes shall
be treated as a single slash."
IIRC, the special treatment ("implementation-defined manner") of pathnames
that begin with two successive slashes is there to recognize a historical
remnant of some Unix system's attempts at rationalizing a "network file
system" into the standard Unix pathname conventions.
If a path started with _one_ slash, it was deemed to name a path on the
local file system. So
/usr/lib
could be found on the currently mounted filesystem tree.
However, if the path started with _two_ slashes, then the first component
was deemed to be a hostname for a network filesystem, and the remaining
path was relative to that host's exported filesystem. So
//LibraryOfCongress/data/cardcatalog/A-D/A101101101
could be found on the server named "LibraryOfCongress".
POSIX and the SUS are attempts to rationalize the behaviours of many
propriatary Unix systems into a single standard, and sometimes carry
caveats to cover where unique Unix systems have deviated from the norm.
This is one such case.