说明:本文为老男孩linux培训某节课前考试试题及答案分享博文内容的一部分,也是独立成题的,你能够点下面地址查看所有的内容信息。
http://oldboy.blog.51cto.com/2561410/791245
2.描述linux下软连接和硬连接的区别。(记时2分钟)
在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 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.
符号连接是一个特殊的文件类型,这不是全部的内核都支持的,System V release 3或更老的系统就缺少符号连接,这个符号链接文件其实是经过名字指向一个不一样的文件(和源文件是不一样的文件),当打开,读取,写入等等大多数操做时,会经过符号连接连接到文件,内核自动找到连接而且操做连接的源,可是一些操做(如:删除)等工做是针对连接自身的,而不是连接的源。
更详细的描述及实践案例见:
老男孩Linux运维实战培训-Linux的硬连接和软连接知识和实践教案和视频精讲
老男孩Linux运维实战培训-Linux文件和目录的属性及权限-001.rar
老男孩Linux运维实战培训-Linux文件系统实战及实践精华教案及视频精讲部分