Hard Link versus Symbolic Link

来源:互联网 发布:电子走势图制作软件 编辑:程序博客网 时间:2024/05/16 05:57

Connotation

link: a named connection between a directory and an object.A user or a program can tell the server where to find an object by specifying the name of a link to the object.

Hard Link:记录inode of target 的 一种文件(a separate directory entry in directory)。因此有“the first hard link is established between the directory and the object(IBM).Users and application programs can add other hard links”。应该不能跨文件系统的记录inode吧

Symbolic Link:a soft link,记录path of target(a path name contained in a file)。因此有“when the system encounters a symbolic link, it follows the path name provided by the symbolic and then continues on any remaining path that follows the symbolic link”。考虑如果没有encounter。

Copy:复制与Hard Link不同,它要拷贝inode指向的数据,当然inode就不同了。


Comparsion

Item Hard Link Symbolic Link Name resolution Faster.A hard link contains a
direct reference to the object. Slower. A symbolic link contains a
path name to the object, which
must be resolved to find the object. Object existence Required.An object must exist in
order to create a hard link to it. Optional. A symbolic link can be
created when the object it refers to does not exist.呼应上面本质 Object deletion Restricted. All hard links to an
object must be unlinked(removed)
to delete the object Unrestricting.An object can be
deleted even if there are symbolic
links referring to it.呼应上面存在无影响 Dynamic objects
(attributes change) Slower. Many of the attributes of an object are stored in each hard link. Changes to a dynamic object, therefore, are slower as the number of hard links to the object increases. Faster.no affect Static objects
(attributes do not
change) Faster. (equals to Name resolution) Slower(equals to Name resolution) Scope 严格,不能跨文件系统 可以跨文件系统


Linux command about link

ls –i #查看inode

ln    #默认创建hard link,目标不可以是目录,可以是文件列表,目的可以是目录,这样没有指定名字的话,就原名。

ln -s #创建 symbolic link

unlink #remove

rm    #remove

touch #change file timestamp