使用符号链接重定向?

Len*_*oyt 4 cd-command symlink

是否可以设置符号链接,以便cd在链接上调用重定向到链接路径?有点像这样:

$ ln /A/B /B/C
$ cd /A/B
$ pwd
/B/C
$
Run Code Online (Sandbox Code Playgroud)

hym*_*mie 7

如果您使用bash,zsh或任何 POSIX shell,则

cd -P
pwd -P
Run Code Online (Sandbox Code Playgroud)

或使其永久化。

  • 在bash:set -P或set -o physical
  • 在zsh:set -w或set -o chaselinks
  • 在其他 POSIX shell 中: alias cd='cd -P'
  • 在tcsh:set symlinks = chase

但是您看到的效果是由外壳创建的,而不是由链接本身创建的。所以你的实际问题的答案是“不”。