Support > About cybersecurity > What is the difference between Linux hard links and soft links?
What is the difference between Linux hard links and soft links?
Time : 2025-07-28 12:17:00
Edit : Jtti

In the Linux file system, hard links and soft links belong to two major categories of file application methods, mainly used to point to existing files. However, there are certain essential differences in the underlying principles, behavior and usage scenarios of the two. Understanding the difference between the two is critical for file management, permission control, backup migration and system operation and maintenance.

Hard links are essentially direct references to file inodes. In the ext series file systems, file data is stored in inodes, and file names are just directory entries pointing to inodes. When a new link is created using a hard link, the system does not create a new file, but allocates a new directory entry for the same inode. This means that no matter how many hard links are created, they all point to the same data area and have the same inode number. Deleting any of the links will not affect the existence of the file data. Only when all links are deleted will the inode be released by the system. Therefore, hard links have exactly the same permissions, content and access methods as the original files. Hard links cannot cross file system boundaries and cannot be used for directories. They are mainly used to improve file availability and redundancy.

Soft links are a special type of file, similar to shortcuts, which contain the target file path itself. When creating a soft link, the system generates an independent file of the symbolic link type, which records the path of the original file. When accessing a soft link, the operating system reads the path it points to and tries to access the target file. If the target file is moved or deleted, the soft link will become invalid, and the "dangling link" state will appear, and the actual content cannot be accessed. Soft links are independent files at the inode level, with their own inodes and file permissions. Its advantage lies in flexibility. It can be created across file systems and also supports linking directories. It is a commonly used path redirection method in system management and program deployment.

From the command implementation, hard links use ln source file target file, while soft links use ln -s source file target link. In the ls -li output, hard links show the same inode number, while soft links show independent inodes and arrows. Soft links are identified in the directory with the type l, and the -> at the end shows the path they refer to. Hard links are completely consistent with the original files and cannot be distinguished by conventional means.

There are also differences in permission behavior. Hard links inherit all permissions of the original file and directly act on the data itself. Editing any hard link will modify the same content. The access rights of a soft link depend on the file it points to. Modifying the link itself will not affect the target content. Soft links themselves have independent permissions, but these permissions usually do not work when accessing the target. The actual control is determined by the target file. If the soft link fails, the access attempt will return "no such file or directory".

In terms of performance, hard links are slightly faster than soft links because the system directly locates the file content through inode without path resolution. When accessing soft links, the path must be resolved first and then the target is located. The more complex the path or the deeper the level, the greater the performance loss. However, this difference is already small in modern file systems and has no significant impact except for large-scale file operations.

The limitation of hard links is that they cannot link directories or cross partitions. In order to prevent circular references and file system confusion, the system blocks support for hard links to directories. Only root users can force creation under specific conditions. Soft links are not subject to this restriction and are widely used in configuration file management, program directory redirection, and multi-version environment deployment. For example, the configuration in /etc/nginx/sites-enabled/ is mostly implemented as soft links. Hard links are more suitable for businesses that require data security redundancy and avoid single-point dependence, such as log file management and dual hot backup in the same directory.

In the deletion operation, deleting a hard link only reduces the reference count of the inode and does not actually remove the data, while deleting a soft link only deletes the link itself and has no effect on the target. Accidental deletion of a hard link may cause the loss of reference counts, while accidental deletion of a soft link affects accessibility. In operations such as system backup and data migration, special attention should be paid to the handling of hard links. Some tools will copy them as independent files, which takes up more space.

/uploads/images/202507/28/2dfdf3ab9e755062ca7bee8d8f468520.jpg  

In development and operation and maintenance scenarios, soft links are more common and are suitable for configuration decoupling, logical structure reconstruction, and application upgrade path switching. Hard links have irreplaceable advantages in log rollback and version control scenarios due to their strong data consistency and low disk consumption. The choice of connection method should be based on file stability, access path, system structure, and deployment mode.

In summary, both hard links and soft links are core file functions provided by the Linux system, each with its own advantages and disadvantages. Hard links focus on data consistency and storage efficiency, and are limited by the file system structure; soft links provide path flexibility and cross-file system operation capabilities, strong compatibility, and adapt to modern distributed deployment models. Understanding the differences between the two can improve file management efficiency and reduce the risks of path errors and file redundancy.

Relevant contents

What are the commonly used traffic encryption technologies for overseas high-defense servers/high-defense IPs? Network performance evaluation and optimization from mainland China to Mexico data center How to set up the whitelist when using Japan's high-defense server What is the latency of accessing Chinese mainland from Mexico cloud server? What is the best tool for testing server speed? Comparison and recommendation of 5 practical speed testing tools Specific strategy for TikTok live broadcast dedicated line anti-blocking IP configuration Technical implementation and security practice of intranet penetration HTTPS encryption settings What does the multi-dimensional evaluation system of the 24-hour on-site operation and maintenance team include? What is a network-level firewall? What are the general characteristics of a firewall? What functions does the HD VOD server have?
Go back

24/7/365 support.We work when you work

Support