linux下软链接和硬链接的区别

    /    2018-10-09

在linux系统中,链接分两种 :一种被称为硬链接(Hard Link),另一种被称为符号链接或软链接(Symbolic Link)。

1)默认不带参数情况下,ln命令创建的是硬链接。

2)硬链接文件与源文件的inode节点号相同,而软链接文件的inode节点号与源文件不同。3)ln命令不能对目录创建硬链接,但可以创建软链接,对目录的软链接会经常被用到。

4)删除软链接文件,对源文件及硬链接文件无任何影响;

5)删除文件的硬链接文件,对源文件及软链接文件无任何影响;

6)删除链接文件的原文件,对硬链接文件无影响,会导致其软链接失效(红底白字闪烁状);

7)同时删除原文件及其硬链接文件,整个文件才会被真正的删除。

8)很多硬件设备中的快照功能,使用的就类似硬链接的原理。

9)软连接可以跨文件系统,硬链接不可以跨文件系统。

附录一:info ln结果摘录及老男孩老师简译参考

A "hard link" is another name for an existing file;
一个硬链接是一个已存在的文件的另一个名字;
the link and the original are indistinguishable. 
这个链接和源文件很难发现有不同的地方(除了名称不一样)。
Technically speaking, they share the same inode, and the inode contains all the information about a file--indeed, it is not incorrect to say that the inode _is_ the file.
从技术上讲,他们共享同一个inode节点号,并且这个节点包含一个文件的所有真实信息(各种属性信息,非文件名和文件内容),把inode当成是文件的说法是不对的。
you cannot make a hard link to a directory, and hard links cannot cross file system boundaries.
你不能为一个目录创建硬链接,并且硬链接不能穿越文件系统边界。
 (These restrictions are not mandated by POSIX, however.)
然而,上述限制在POSIX中是不被限制的。
"Symbolic links" ("symlinks" for short), on the other hand, are a special file type (which not all kernels support: System V release 3 (and older) systems lack symlinks) in which the link file actually refers to a different fileby name.  When most operations (opening,reading, writing, and so onare passed the symbolic link file, the kernel automatically "dereferences" the link and operates on the target of the link.  But some operations (e.g., removing) work on the link file itself, rather than on its target. 
符号链接是一个特殊的文件类型,这不是所有的内核都支持的,System V release 3或更老的系统就缺乏符号链接,这个符号连接文件实际上是通过名字指向一个不同的文件(和源文件是不同的文件),当打开,读取,写入等等大多数操作时,会通过符号链接链接到文件,内核自动找到链接并且操作链接的源,但是一些操作(如:删除)等工作是针对链接自身的,而不是链接的源。


(10)

分享至