Ln
Syntax: ln [-S] [source file] [target file]
Note: Create a symbolic or hard link.
Parameters:
-S: Provides symbolic links. Hard links are used by default.
Example:
0. Original information:
$Ll
-RW-r -- 1 Root 13476 Jun 26 :31 passwd
1. Hard link information:
$Ln passwd-hard
$Ll
Total 32
-RW-r -- 2 root Root 13476 Jun 26 :31 passwd
-RW-r -- 2 root Root 13476 Jun 26 :31 passwd-hard
Note that the number above is changed to 2, which indicates that inodes is occupied.
2. Symbolic Link information:
$ Ln-s passwd-soft
$ LL
-RW-r -- 2 root Root 13476 Jun 26 :31 passwd
-RW-r -- 2 root Root 13476 Jun 26 :31 passwd-hard
Lrwxrwxrwx 1 Root 6 Jun 26 :37 passwd-Sofe-> passwd
Note that passwd-soft points to another file, and the front attribute is L. In addition, it is an independent file.
Delete passwd first, and use more to view the content.
3. Use more:
$Rm passwd
RM: Remove regular file 'passwd '? Y
$More passwd-hard
......... (Normal display)
$More passwd-soft
Passwd-soft: no such file or directory
Glossary:
Block
It is the minimum unit that a disk can record. It is composed of several sectors. Therefore, the size is generally N * 512 bytes, for example, 4 K.
Inode.
A block is the region where the file content and data are recorded. inode records the attributes of the file and the information of the block in which the file is stored. Therefore, each file occupies one inode. When a file is to be searched in Linux, it first searches for inode.
Table, find the attributes and Data Location of the file, and then find the block where the data is stored to retrieve the data. The number of inode has been set at the beginning. The setting method is usually "Hard Disk size/One capacity", which is better than the block size. For example, you just set the block to 4 K, so this capacity
It can be about 8 KB. Therefore, if a 1 GB hard disk is divided into 8 K inode numbers, there will be 131072 inode. The size of an inode is 128 bytes, so that we can clearly know that after a partition is formatted as a file system, there will basically be two blocks of inode table and data area, one is used to record the attribute information of the file and the block placed in the file, and the other is used to record the content of the file.
Hard Link
As mentioned earlier, when the system wants to read a file, it first reads the inode table and then extracts the data from the data area based on the inode information for backup. A hard link is to create an inode link to the block placed in the file. That is
In fact, the content of your file will not change during the hard link, but the original inode and later inode can be used to specify the location of the file during the query. Therefore, the result of Reading Two inodes is to access the content of the same file. However, there is a problem as inode links to block blocks, while "directory" only consumes inode. In this way, hard links cannot link directories. Therefore, hard links have two biggest restrictions:
1. Cross-file system is not allowed, because different file systems have different inode tables;
2. The directory cannot be linked.
Symbolic Link
The symbolic link is easier to understand than a hard link. Basically, it creates an independent file, which directs the data read operation to the file linked to it. Because only the file is used as the pointing action,
When the source file is deleted, the file linked with the symbol cannot be opened, and the screen displays "cannot open a file ". Therefore, the hard link is safer, because even if an inode is deleted, the file can be found as long as there is an inode.