我在主文件夹中创建了一个到另一个目录的符号链接:
$ pwd
/home/user1
$ ln -s /usr/local/dir/ shortcut
$ ls -l
................................... shortcut -> /usr/local/dir/
$ cd shortcut
$ pwd
/home/user1/shortcut
我确实以该目录结尾,因此我可以看到其中的所有文件,但是该目录pwd
很混乱,可能会导致问题。有没有更好的方法可以使它充当快捷方式并/usr/local/dir
在我进入时实际显示cd shortcut
而不是显示新路径?
两者cd
和pwd
都有使用物理目录结构的标志。
$ cd --help
...
-P use the physical directory structure without following
symbolic links: resolve symbolic links in DIR before
processing instances of `..'
...
例如
$ cd /var/tmp
$ ln -s /home/user test
$ cd -P test
$ pwd
/home/user
上面,我们使用cd -P
了物理目录结构,因此现在pwd
为我们提供了物理路径。
$ pwd
...
-P print the physical directory, without any symbolic links
...
例如
$ cd /var/tmp
$ ln -s /home/user test
$ cd test
$ pwd
/var/tmp/test
$ pwd -P
/home/user
上面,我们cd
像往常一样进入目录,因此pwd
给出了符号路径。使用pwd -P
将给出物理路径。
如果您正在使用bash
,则可以告诉它完全忽略符号链接,而只需运行即可使用物理目录结构set -P
(的简写set -o physical
,请参见`bash手册页)。其他外壳也可能这样做。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句