linux soft link and a hard link (summary)

Reference blog:
https://www.cnblogs.com/fengdejiyixx/p/10821820.html
https://www.runoob.com/linux/linux-comm-ln.html
https://www.cnblogs.com/crazylqy /p/5821105.html

Notes:

    当划分磁盘分区并格式化的时候,整个分区会被划分为两个部分,即inode区和data block(实际数据放置在数据区域中)这个inode即是(目录、档案)文件在一个文件系统中的唯一标识,需要访问这个文件的时候必须先找到并读取这个 文件的 inode。 Inode 里面存储了文件的很多重要参数,其中唯一标识称作 Inumber, 其他信息还有创建时间、修改时间 、文件大小、属主、归属的用户组、读写权限、数据所在block号等信息。

    A hard link is the B (A and B is a file name), then the same directory entry in the directory entry A and B of the inode number of the inode number, i.e., a node corresponding to two different inode file name, two file names point to the same document, a and B, the file system is completely equal. If you delete one of them, a no effect on another. Each additional file name, the inode number of links is increased by one on each corresponding to delete a file name, the inode number of links on a reduced until it is recovered as 0, and the inode corresponding data block. Note: File and file names are different things, rm A just delete the file name A, and A corresponding data block (file) only reduced to 0 when the system will be recovered in the number of links to the inode.

    A soft link of B (A and B are the file name), the directory entry directory entry in the A and B of the inode number of the inode numbers are not the same, A and B are two different points of inode, then directed two different data blocks. However, data block A is stored in the path name only B (found in accordance with this directory entry B). Is the "master-slave" relationship between A and B, if B is deleted, A still exist (because the two are different files), but it points to an invalid link.

Created:

        1.软链接(符号链接) ln -s   目标文件  链接名 
        2.硬链接 (实体链接)ln       目标文件  链接名 

The main parameters:

        -b 删除,覆盖以前建立的链接
        -d 允许超级用户制作目录的硬链接
        -f 强制执行
        -i 交互模式,文件存在则提示用户是否覆盖
        -n 把符号链接视为一般目录
        -s 软链接(符号链接)
        -v 显示详细的处理过程

the difference:

   软链接:

        1.软链接,以路径的形式存在,类似于Windows操作系统中的快捷方式
        2.软链接可以跨文件系统
        3.软链接可以对一个不存在的文件名进行链接
        4.软链接可以对目录进行链接
        5.软链接原文件/链接文件拥有不同的inode号,表明他们是两个不同的文件
        6.当源文件目录改变后,软连接访问不到

   硬链接:

        1.硬链接,以文件副本的形式存在,但不占用实际空间
        2.不允许给目录创建硬链接(可以通过参数添加但仅限root用户)
        3.硬链接只有在同一个文件系统中才能创建
        4.不能对不存在的文件创建硬链接
        5.硬链接原文件/链接文件公用一个inode号,说明他们是同一个文件
        6.当源文件目录改变后,硬连接可以访问

scenes to be used:

    软连接:
        1.便于文件的管理,比如把一个复杂路径下的文件链接到一个简单路径下方便用户访问。
        2.节省空间解决空间不足问题,某个文件文件系统空间已经用完了,但是现在必须在该文件系统下创建一个新的目录并存储大量的文件,那么可以把另一个剩余空间较多的文                 件系统中的目录链接到该文件系统中。

    硬链接:
        硬链接的作用之一是允许一个文件拥有多个有效路径名,比如备份文件,快照。

Guess you like

Origin www.cnblogs.com/vinic-xxm/p/11362755.html