据help cd
,
Options:
-L force symbolic links to be followed: resolve symbolic
links in DIR after processing instances of `..'
-P use the physical directory structure without following
symbolic links: resolve symbolic links in DIR before
processing instances of `..'
换句话说,-L
意味着使用逻辑结构,而-P
使用实际的物理目录结构。
逻辑结构是这样的,
$ tree a
a
└── b
└── symlink -> ..
当你去的时候,实际的物理结构a/b/symlink
是,
a
如果你想使用真实的 ..
,那么你还必须使用cd -P
:
The -P option says to use the physical directory
structure instead of following symbolic links (see
also the -P option to the set builtin command);
the -L option forces symbolic links to be followed.
一个例子,
$ cd
$ cd a/b/symlink # physical location is at a/
$ cd .. # now is at a/b
$ cd symlink # goes back to a/b/symlink
$ cd -P .. # follow physical path (resolve all symlinks)
$ pwd -P # -P is optional here to show effect of cd ..
/home/sarnold
$