指向绝对路径的链接

发布于 2024-07-17 07:29:48 字数 89 浏览 6 评论 0原文

链接应始终指向绝对路径而不是从当前目录指向,这是一个好习惯吗?

我正在谈论这个参考 - 我需要维护软件并且其所有以前的版本应该始终指向最新版本。

Is it a good practice that links should always point to absolute path rather than pointing from current directory?

I am talking this with reference - where i need to maintain software and all its previous versions should always point to latest version.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

紙鸢 2024-07-24 07:29:48

定义“良好实践”。 链接是否指向绝对路径取决于文件之间的关系。

如果文件始终处于相同的相对位置,但可以移动(例如 bin/ 中的别名),则它们应该是相对的。 如果实际文件位于已知位置(例如,您想要将默认配置文件链接到~/.config),则使用绝对路径。

Define "good practice". Whether a link points to an absolute path or not depends on the relationship between the files.

If the files are always in the same relative positions, but could be moved around (eg aliases in bin/), they should be relative. If the actual file is in a known location (eg, you want to link a default config file to ~/.config), then use an absolute path.

夏花。依旧 2024-07-24 07:29:48

取决于你想做什么。 我的 Linux 系统有两种符号链接。

find /usr /bin /lib -type l -print0 | xargs -0 ls -ld | less

Depends on what you want to do. My Linux system has both kinds of symlinks.

find /usr /bin /lib -type l -print0 | xargs -0 ls -ld | less
雨夜星沙 2024-07-24 07:29:48

我不认为这有什么“好的做法”。 有不同的用例。

例如,如果我将树与本地安装的程序存储在 /home/.../application 中,我可能希望将“默认配置”符号链接到某些没有绝对路径的特定配置。 这样,当我将整个树移动到 /home/.../application-other-instance 时,配置文件的链接保持正确。

另一方面,如果我想在本地目录中引用 /etc/... 中的某些全局文件,我将使用绝对路径符号链接来完成。 这保证了我在移动的任何地方都指向同一个文件。

只要想想你想要实现什么,相对/绝对路径的决定要么是显而易见的,要么是无关紧要的。 唯一的“永远不要这样做”规则可能是:永远不要通过 ../../../../../../../xxx 链接到 root dir /xxx 中的任何内容

I don't think there's a "good practice" for that. There are different use cases.

For example if I store a tree with a program installed locally in /home/.../application, I may want to symlink "default config" to some specific config without an absolute path. That way, when I move the whole tree to /home/.../application-other-instance, the link to the config file stays correct.

On the other hand, if I want to reference some global file in /etc/... in a local dir, I will do it with an absolute path symlink. That guarantees that I'm pointing to the same file anywhere I move.

Just think what do you want to achieve, and the relative / absolute path decision will be either obvious, or irrelevant. Only "never do that" rule is probably: Never link to anything in root dir /xxx, via ../../../../../../../xxx

半透明的墙 2024-07-24 07:29:48

我认为我不能同意这一概括。

在某些情况下,相对链接肯定更有意义。 例如,使用项目的目录树。 如果项目被备份或移动(甚至复制)到另一个地方,绝对链接可能会造成混乱和/或灾难性的。

即使您谈论的是系统范围的工具,也会存在相对链接有意义的情况,而其他时候则没有意义。 将指向非常通用的工具(如 grep )的链接与位于同一主机上的 gnu 编译器工具的多个版本和目标风格之类的链接进行比较。 在后一种情况下,可能需要到特定工具版本的绝对链接。

这一切都取决于你在每种情况下真正想做的事情。 一般的答案是没有通用的答案。

I don't think I can agree with that as a generalization.

There are definitely cases where a relative link makes more sense. With a directory tree of a project, for example. If the project is backed-up, or moved (even duplicated) into another place, absolute links could be confusing and/or disastrous.

Even if you are talking about system-wide tools, there will be cases where relative links make sense, and other times not. Compare having a link to a very generic tool, like grep , versus something like multiple versions and target flavors of the gnu compiler tools living on the same host. In the latter case, absolute links to the specific tool versions will probably required.

It all comes back to what you really want to do in each case. The general answer is that there is no generalized answer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文