在不同目录中创建链接(Linux/UNIX)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在不同目录中创建链接(Linux/UNIX)相关的知识,希望对你有一定的参考价值。

When using `ln` to create a link in a different directory, the semantics of creating hard and symbolic links differ. That is because a hard link contains a direct reference to its target's data, while a symbolic link is just a string containing a (possibly relative) path. You can get around this by using absoute paths, but then moving a subtree will break the symlink.

Just to recap, the other main differences between hard and symbolic links: Symbolic links can be left dangling when their target is removed; hard links cannot. Symbolic links can point to files on other partitions or disks, while hard links cannot.
  1. # create hard link in subdir which points to ../otherdir/file
  2. ln ../otherdir/file subdir/link
  3.  
  4. # create symbolic link in subdir which points to ../otherdir/file
  5. ln -s ../../otherdir/file subdir/symlink
  6. # note the additional "../" which compensates the subdir

以上是关于在不同目录中创建链接(Linux/UNIX)的主要内容,如果未能解决你的问题,请参考以下文章

在Ubuntu中创建目录的符号链接[关闭]

如何在像“ln -s TARGET DIRECTORY”这样的目录中创建符号链接?

在 C 中创建模块系统(动态加载)

为啥我的符号链接没有链接,而是在我试图链接的目录中创建一个文件

sh 在当前工作目录中创建链接。一个“ln -s”包装器。

Ionic - 在 android 的不同目录中创建 SQLite 数据库