符号链接CD的行为/ bash的 [英] Behavior of cd/bash on symbolic links
问题描述
假设我在我的个人文件夹中的文件夹〜/ A / B,并将该文件夹B包含
一个符号链接'..'名为符号链接。然后,我执行以下操作
庆典:
Assume I have the folders ~/a/b in my home folder, and the folder b contains a symbolic link to '..' named 'symlink'. Then I perform the following actions in bash:
hm@mach:~$ cd a/b/symlink
hm@mach:~/a/b/symlink$ pwd -P
/home/hm/a
hm@mach:~/a/b/symlink$ cd ..
hm@mach:~/a/b$ pwd -P
/home/hm/a/b
PWD -P打印当前工作目录,取消引用所有符号链接。
为什么工作目录/ home / HM / A /末B,而不是/家/嗯?
pwd -P prints the current working directory, dereferencing all symbolic links. Why is the working directory /home/hm/a/b at the end, and not /home/hm?
推荐答案
庆典
是被友好;当你 CD /到/ A /符号链接/
,外壳记得原来的位置(在 $ OLDPWD
)和意志使用的是的目录,当你 CD ..
要回到你刚才是在目录中的假设下。
bash
is being "friendly"; when you cd /into/a/symlink/
, the shell remembers the old location (in $OLDPWD
) and will use that directory when you cd ..
under the assumption that you want to return to the directory you were just in.
如果您想使用的真正的 ..
,则还必须使用 CD-P
:
If you want to use the real ..
, then you must also use 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
$ cd -P ..
$ pwd -P
/home/sarnold
$
这篇关于符号链接CD的行为/ bash的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!