如何将我的密码更改为符号链接目录的真实路径?
这是一个相当基本的 *nix 问题:
给定以下符号链接创建:
ln -s /usr/local/projects/myproject/ myproject
...从我的主目录 /home/jvf/,输入 myproject 符号链接给我一个 pwd <强>/home/jfv/myproject/。现在,我想输入我符号链接到的目录的父目录,但是 cd .. 命令只会将我带回到我的主目录 /home/jfv/< /强>。无论如何,有没有办法逃避我输入的符号链接路径,而是让 pwd 等于 myproject 目录的实际路径。也就是说,将我的密码从 /home/jfv/myproject/ 更改为 /usr/local/projects/myproject/?
谢谢 :)
Here's a rather elementary *nix question:
Given the following symlink creation:
ln -s /usr/local/projects/myproject/ myproject
... from my home directory /home/jvf/, entering the myproject symlink gives me a pwd /home/jfv/myproject/. Now, I would like to enter the parent directory of the directory I've symlinked to, but the cd .. command will only bring me back to my home directory /home/jfv/. Is there anyway to escape the symlink trail that I've entered, and instead have a pwd equal to the actual path of the myproject directory. That is, changing my pwd from /home/jfv/myproject/ into /usr/local/projects/myproject/?
Thanks :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
只需使用
-P
(物理)标志:Just use
-P
(physical) flag:如果您执行以下操作,应该没问题。
1) 首先,跟随符号链接:
2) 现在执行以下命令:
3) 现在,您可以检查您的位置,您将看到您位于物理目录上
输出将如下所示:
现在,您所做的一切都会是本地的而不是符号链接上的。
If you do the following you should be OK.
1) First you follow your symlink:
2) Now you execute the following command:
3) Now, you can check your location and you will see that you are on the physical directory
The output will be as follows:
Now, everything you do will be local and not on the symlink.
以编程方式,您可以使用 getcwd 库函数来执行此操作:
Programmatically, you would do this with the getcwd library function: