当路径包含符号链接时,如何将一个目录移回 unix / linux?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10960883/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to move one directory back in unix / linux when path contains symbolic links?
提问by manav m-n
I have created a symbolic link to a deeply nested directory. Using symbolic link i can move to that directory from my home directory. I want to move one directory back from the target directory but the shell comes back to the home directory.
我创建了一个指向深层嵌套目录的符号链接。使用符号链接,我可以从我的主目录移动到该目录。我想将一个目录从目标目录移回,但 shell 返回到主目录。
[root@pe1800xs ~]# pwd
/root
[root@pe1800xs ~]# mkdir -p abc/def/ghi/jkl/mno/pqr
[root@pe1800xs ~]# ln -s abc/def/ghi/jkl/mno/pqr/ xyz
[root@pe1800xs ~]# cd xyz
[root@pe1800xs xyz]# pwd
/root/xyz
[root@pe1800xs xyz]# pwd -P
/root/abc/def/ghi/jkl/mno/pqr
[root@pe1800xs xyz]# cd ..
[root@pe1800xs ~]# pwd
/root
What I want to achieve is that when I do cd..
in pqr
directory the shell should come to mno
directory.
我想要实现的是,当我cd..
在pqr
目录中执行时,shell 应该进入mno
目录。
采纳答案by Fèlix Galindo Allué
You must use
你必须使用
cd -P xyz
to enter into that directory to follow the original structure of folders, then you can move as you wish because you have resolved the link to the real path.
进入该目录以遵循文件夹的原始结构,然后您可以随意移动,因为您已解析到真实路径的链接。
回答by Fatih Arslan
You have to pass -P
option:
你必须通过-P
选项:
cd -P ..