Linux文件系统符号链接(软链接)和硬链接的区别
Linux 文件系统 符号链接(软链接)和 硬链接的区别


首先明白一点:Linux下, 对于一个文件来说,有唯一的索引接点(inode)与之对应,而对于一个索引接点号,却可以有多个文件名与之对应。因此,在磁盘上的同一个文件可以通过不同的路径去访问该文件。


官方描述:
  A "hard link" is another name for an existing file; the link and the
original are indistinguishableTechnically 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.
Most systems prohibit making a hard link to a directory; on those where
it is allowed, only the super-user can do so (and with caution, since
creating a cycle will cause problems to many other utilities). Hard
links cannot cross file system boundaries. (These restrictions are not
mandated by POSIX, however.)
   "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 file,【 可以理解为一个文件的快捷方式】 by name. When most operations (opening,
reading, writing, and so on) are 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. The owner and group of a


硬链接文件有两个限制 
1)、不允许给目录创建硬链接; 
2)、只有在同一文件系统中的文件之间才能创建硬链接。


硬连接的作用是允许一个文件拥有多个有效路径名,这样用户就可以建立硬连接到重要 
    文件,以防止“误删”的功能。其原因如上所述,因为对应该目录的索引节点有一个以上的连接。只删除一个连接并不影响索引节点本身和其它的连接,只有当最后一个 
    连接被删除后,文件的数据块及目录的连接才会被释放。
    硬链接可以认为不是一个文件,它只是实际文件的一个别名,它的作用是防止真实文件被误操作,给一个文件建立硬链接后,他们互为别名,删除其中任意一个, 
    这样用RM命令只会删除该别名,实际文件并不会被删除。只有链接数为0时,才会删除原始文件。 

软链接是另一个文件,作用可以理解为一个指针,作用在这个文件上的操作 除了删除以外,都直接转向实际指向文件,由于是一个真实的文件所以占用磁盘空间。 


© 2009-2020 Zollty.com 版权所有。渝ICP备20008982号