The difference between soft links and hard links in Linux

The difference between soft links and hard links in Linux

1. Concept

​ Link file: It is a file in the Linux operating system, mainly used to solve the problem of file sharing and use, and the link method is divided into two types-soft link and hard link.

​ inode: is the area in the file system that stores file meta information (creator, size, date, etc.) of the file, called the node index.

​ Soft link (soft link): also known as symbolic link (Symbolic Link), similar to the shortcut file in the Windows operating system, the file has its own name, inode and physically stored file data (recording another file's The pathname points to), accessing the file will be redirected to the source filename pointed to by the soft link.

​ Hard link: It is equivalent to creating a file alias for the file corresponding to the current file name. The inode corresponding to the current file name and the file alias is the same as the physically stored file data. Accessing the file alias is the same as accessing The current filename is the same.

insert image description here


2. Difference

  • Delete the source file, the soft link will become invalid, but the hard link will not;
  • Soft links can create links for files and directories (allowing nonexistent), hard links can only create links for files;
  • Soft links can cross file systems, and hard links must be in the same file system;
  • The file permissions of the soft link can be different from the source file, and the file permissions of the hard link must be the same as the source file;

3. Application scenarios

​ Soft link: as a shortcut to an executable file.

​ Hard link: Back up important files.


4. Create

# 软链接(源文件必须写成绝对路径)
ln -s SOURCE TARGET

[root@localhost ~]# ln -s /home/file /tmp/soft_file

# 硬链接
ln SOURCE TARGET

[root@localhost ~]# ln /home/file /tmp/hard_file

Guess you like

Origin blog.csdn.net/weixin_51123079/article/details/128044316