Linux systems have soft links and hard links, so-called soft links similar to Windows system shortcuts, if the source file is deleted, soft links will fail. The hard link is different, even if the source file is deleted, the file still exists, this is why? Let me give you a brief explanation of why:
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/85/2E/wKioL1ecKjiA4zXKAARNO-dL4vQ029.jpg "title=" Inode.jpg "alt=" Wkiol1eckjia4zxkaarno-dl4vq029.jpg "/>
Soft Links:
This is a simple diagram of a Linux storage file that I drew, the connection of the soft link is that, in the Inode table, the location of the pointer is not a pointer, but the metadata path of a file is stored, through the path to find the file metadata, and then find the file itself. Example:/ROOT/1 is the original file,/ROOT/2 is a soft link file
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/85/2F/wKioL1ecMnqRFQwbAAAIwJpbTVE950.png "title=" Qq20160730125023.png "alt=" Wkiol1ecmnqrfqwbaaaiwjpbtve950.png "/>
The first behavior inode number, these two files have different inode number, 2 file file size is 1 bytes, this byte is written "1", that is, the name of the connection file, if the name of the connection file is 123, then this will be 3 bytes.
Features of soft Links:
Soft links have their own file attributes and permissions, etc.;
You can create a soft link to a nonexistent file or directory;
Soft link can cross file system;
Soft links can be created on files or directories;
When you create a soft link, the link count i_nlink not increase;
Deleting a soft link does not affect the file being pointed to, but if the original file being pointed to is deleted, the associated soft connection is called a dead link (that is, dangling link, if it is re-created by pointing to the path file, the dead link can revert to the normal soft link).
Hard Links:
The reason for hard links is that different files have the same inode number, and an inode number can have different file names, but only one copy of the data is saved. If one of the filenames is deleted, only the association of the file name and inode number is severed, and no other links and data are affected.
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/85/2F/wKiom1ecNe_ShJQ7AAAHZoOPmo8412.png "title=" 123. PNG "alt=" Wkiom1ecne_shjq7aaahzoopmo8412.png "/>
These two files have the same inode number, including the same permission size, which is the hard link.
Features of hard Links:
The file has the same inode and data block;
Only files that already exist can be created;
Cannot cross file system for hard link creation;
The directory cannot be created, only the file can be created;
Deleting a hard-link file does not affect other files that have the same inode number.
How to create a soft link:
Ln-s TARGET Link_name
Ways to create a hard link
ln TARGET link_name
-F: Delete the file with the Dist file name at the end of the link
-D: Allow system managers to hard-link their own directories
-I: Ask before deleting the file with the Dist file name
- N: When making a soft link, treat the dist as a generic file
-S: Soft junction (symbolic Link)
- V: Displays the file name before the link
-B: Files that are overwritten or deleted at the time of the link are backed up
-S SUFFIX: Add the backed up files with SUFFIX tails
-V Method: Specify how the backup should be
--help: Show Auxiliary Instructions
--version: Display version
This article is from the "zebra930" blog, make sure to keep this source http://zebra930.blog.51cto.com/11736340/1832014
Understanding Linux Hard links and soft links