如何将我的密码更改为符号链接目录的真实路径?

发布于 2024-08-23 00:37:08 字数 525 浏览 5 评论 0原文

这是一个相当基本的 *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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

将军与妓 2024-08-30 00:37:08

只需使用 -P (物理)标志:

pwd -P

cd -P ..

Just use -P (physical) flag:

pwd -P

cd -P ..
风为裳 2024-08-30 00:37:08

如果您执行以下操作,应该没问题。

1) 首先,跟随符号链接:

[jfv@localhost ~]$ cd myproject

2) 现在执行以下命令:

[jfv@localhost myproject]$ cd -P ./

3) 现在,您可以检查您的位置,您将看到您位于物理目录上

[jfv@localhost myproject]$ pwd

输出将如下所示:

/usr/local/projects/myproject

现在,您所做的一切都会是本地的而不是符号链接上的。

If you do the following you should be OK.

1) First you follow your symlink:

[jfv@localhost ~]$ cd myproject

2) Now you execute the following command:

[jfv@localhost myproject]$ cd -P ./

3) Now, you can check your location and you will see that you are on the physical directory

[jfv@localhost myproject]$ pwd

The output will be as follows:

/usr/local/projects/myproject

Now, everything you do will be local and not on the symlink.

七七 2024-08-30 00:37:08

以编程方式,您可以使用 getcwd 库函数来执行此操作:

#include <unistd.h>
#include <stdio.h>

int main(int argc, char **argv)
{
    char buf[1024*1024L];
    char *cwd;

    cwd = getcwd(buf, sizeof buf);
    if (cwd == NULL) {
        perror("getcwd");
        return 1;
    }
    printf("%s\n", cwd);
    return 0;
}

Programmatically, you would do this with the getcwd library function:

#include <unistd.h>
#include <stdio.h>

int main(int argc, char **argv)
{
    char buf[1024*1024L];
    char *cwd;

    cwd = getcwd(buf, sizeof buf);
    if (cwd == NULL) {
        perror("getcwd");
        return 1;
    }
    printf("%s\n", cwd);
    return 0;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文