当前位置: 技术问答>linux和unix
讨论: linux系统的软连接
来源: 互联网 发布时间:2016-04-04
本文导语: 硬连接: 比如在目录/home 下建立一个硬连接到/etc/passwd 文件, 其实是在该目录写入了 /etc/passwd的inode位置信息,当访问/home/passwd时,会访问/etc/passwd 文件的inode 信息,然后再访问passwd的block内容。 那软连接是...
硬连接:
比如在目录/home 下建立一个硬连接到/etc/passwd 文件, 其实是在该目录写入了 /etc/passwd的inode位置信息,当访问/home/passwd时,会访问/etc/passwd 文件的inode 信息,然后再访问passwd的block内容。
那软连接是怎么回事,没搞明白?请高手解答一下? 不胜感激!
比如在目录/home 下建立一个硬连接到/etc/passwd 文件, 其实是在该目录写入了 /etc/passwd的inode位置信息,当访问/home/passwd时,会访问/etc/passwd 文件的inode 信息,然后再访问passwd的block内容。
那软连接是怎么回事,没搞明白?请高手解答一下? 不胜感激!
|
我的理解,
软连接 有点类似 windows的快捷方式,如果你删除了该原来的文件,该软连接就没内容,或没法执行了
如硬连接,其实是连接到inode,原来的文件名,其实也是链接该inode, 那删除原来的文件,保存在那个inode的数据还在,所以,硬链接还是可正常读到原来的内容。
软连接 有点类似 windows的快捷方式,如果你删除了该原来的文件,该软连接就没内容,或没法执行了
如硬连接,其实是连接到inode,原来的文件名,其实也是链接该inode, 那删除原来的文件,保存在那个inode的数据还在,所以,硬链接还是可正常读到原来的内容。
|
两种连接都不占用额外磁盘空间
|
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.
On all existing implementations, 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.)
"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. *Note Symbolic Links:
(libc)Symbolic Links.
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.
On all existing implementations, 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.)
"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. *Note Symbolic Links:
(libc)Symbolic Links.
|
对呀,软连接自己是个文件,占用空间。