Analysis of the principles and usage of Linux hard links and soft links

Analysis of the principles and usage of Linux hard links and soft links

In the Linux system, there is a kind of file called link file, which can be used to solve file sharing. There are two types of links: hard link and soft link or symbolic link.

Hard link concept

A hard link (also called a link) is one or more file names of a file.

A hard link is a link made through an index node. In the Linux file system, no matter what type of file is stored in the disk partition, it will be assigned a number, which is called the inode number.

Index) or Inode, which is the unique identifier of a file or directory in a file system. The actual data of the file is placed in the data area (data block), which stores important file parameter information, that is, metadata, such as creation time, modification time, file size, owner, user group, read and write permissions, data block number, etc.

After the hard link is established, the source file and the link file are synchronized, and any modification to either file will be modified

Establishing links can save space. You only need to maintain the link relationship without copying the file.

Soft link concept

A soft link (also called a symbolic link) is similar to a shortcut in the Windows system. Unlike a hard link, a soft link is just an ordinary file, but the data block content is a bit special. The content stored in the file user data block points to the path name of another file. This method can quickly locate the source file entity pointed to by the soft link. Soft links can be created for files or directories.

Soft link function:

  • It is convenient for file management, for example, linking a file in a complex path to a simple path for user access.
  • Save space to solve the problem of insufficient space. If a file system has run out of space, but now you must create a new directory under the file system and store a large number of files, you can link a directory in another file system with more remaining space to the file system.
  • Deleting a soft link does not affect the file it points to, but if the original file it points to is deleted, the related soft link becomes a dead link.

The essential difference between hard links and soft links

A hard link can be considered as a file with two file names; a soft link is a new link file created by the system, which points to the file it refers to.

Limitations of Hard Links

  • Soft links can cross file systems; hard links cannot
  • A soft link can link to a non-existent file; a hard link cannot
  • Soft links can connect directories, but hard links cannot
  • Soft links overcome the limitations of hard links. Based on this, focus on soft links. A soft link is also called a symbolic link, which is equivalent to a shortcut in Windows.

Create a soft link

ln -s src_file ln_file

Deleting soft links

rm ln_file

Note: For directory soft leveling

rm ln_dir is to delete the soft link

rm ln_dir/ deletes the files in the directory ln_dir. Of course, the files in the source directory will also be deleted (synchronously).

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • A detailed introduction to Linux hard links and soft links
  • What are Linux soft links and Linux hard links
  • Distinguishing between Linux hard links and soft links

<<:  Detailed explanation of how to create multiple instances of MySQL 5.6 in centos7 environment

>>:  JavaScript to implement limited time flash sale function

Recommend

Navicat connects to MySQL8.0.11 and an error 2059 occurs

mistake The following error occurs when connectin...

How to build a new image based on an existing image in Docker

Building new images from existing images is done ...

Implementation of CSS scroll bar style settings

webkit scrollbar style reset 1. The scrollbar con...

Specific method to add foreign key constraints in mysql

The operating environment of this tutorial: Windo...

Problems and solutions encountered when connecting node to mysql database

I installed a new version of MySQL (8.0.21) today...

How to solve the problem that Docker container has no vim command

Find the problem Today, when I tried to modify th...

Two ways to exit bash in docker container under Linux

If you want to exit bash, there are two options: ...

CSS animation property usage and example code (transition/transform/animation)

During development, a good user interface will al...

JavaScript Basics: Immediate Execution Function

Table of contents Immediately execute function fo...

How to write beautiful HTML code

What Beautiful HTML Code Looks Like How to write ...

How to run .sh files in Linux system

There are two ways to run .sh files in Linux syst...

Detailed explanation of how to use Tomcat Native to improve Tomcat IO efficiency

Table of contents Introduction How to connect to ...

How to use tcpdump to capture packets in Linux system

Let me look at the example code first: 1. Common ...

CSS hacks \9 and \0 may not work for hacking IE11\IE9\IE8

Every time I design a web page or a form, I am tr...