[Linux] Hard link and soft link

Before distinguishing between hard links and soft links, we must first understand the related concepts of inode. The file system includes an inode area and a data area. The inode area includes inode table, inode bitmap, and block bitmap.
inode full name index node, that is, the index nodes for metadata information stored files. In the Linux operating system, each file corresponds to an inode number, and the system uses the inode number to identify the accessed file.
Some basic commands about inodes are as follows:
stat filename to view detailed information of files (including inode information);
ls -li long format to display inode node information;
df -i to view the number of inodes and spare numbers;
df -h to view disk usage.
Linking files refers to directly creating links between two files, similar to shortcuts under Windows. There are two ways to link, hard link and soft link.

  • Hard link: Multiple file names point to the same inode number. Different file names can access the same content. Modifying the file content will affect the access of all file names. Deleting a hard-linked file will not affect other files with the same inode number. File hard links cannot cross file systems and cannot create hard links to directories.
    The creation of hard link: ln original file name, new link name
  • Soft link: The content stored in the soft link data block is the path name of another file. The soft link is an ordinary file with its own inode number and user data block. Basically, the soft link can be regarded as a shortcut. The soft link is a kind of "independent" file, so after deleting the source file, the soft link file still exists, but the content of the file it "points to" cannot be viewed. Soft links can span file systems or can be established for directories.
    Creation of soft link: ln -s original file name to create new link name

Guess you like

Origin blog.csdn.net/weixin_45177279/article/details/114993278