Home > Common Problem > body text

What is the difference between soft links and hard links in linux

小老鼠
Release: 2023-06-07 15:18:44
Original
10348 people have browsed it

The difference between soft links and hard links in Linux: 1. Soft links exist in the form of paths, and hard links exist in the form of file copies, but do not occupy actual space; 2. Soft links can cross file systems, and hard links Links are not allowed; 3. Soft links can link to a file name that does not exist, and hard links can only be created in the same file system; 4. Soft links can link to directories, but hard links do not allow creating links to directories.

What is the difference between soft links and hard links in linux

#The operating system of this tutorial: linux5.18.14 system, Dell G3 computer.

In the Linux file system, there is a so-called link, which we can think of as an alias for a file. Links can be divided into two types: hard link and symbolic link. ), a hard link means that a file can have multiple names, while a soft link generates a special file whose content points to the location of another file. Hard links exist in the same file system, but soft links can span different file systems.

The difference between soft links and hard links (popular):

A hard link can be considered as a file with two file names;

And a soft link The link is a new link file created by the system, which points to the file it refers to

If the source file is renamed, the soft link will not be available (the source file cannot be found); the hard link can access the source file normally;

Modify soft links, hard links and source files, and access to all three changes simultaneously.

Soft link:

Soft link exists in the form of a path. Similar to shortcuts in the Windows operating system

Soft links can cross file systems, but hard links cannot.

Soft links can link to a non-existent file name

Soft links can link to directories

Hard links:

Hard links exist in the form of file copies. But it doesn't take up actual space.

Creating hard links to directories is not allowed

Hard links can only be created in the same file system

There are two points to note here:

First, the ln command will maintain the synchronization of each linked file, that is to say, no matter where you change, other files will have the same changes;

Second , ln links are divided into soft links and hard links. The soft link is the ln -s source file target file. It will only generate a mirror image of the file at the location you selected and will not occupy disk space. The hard link ln Source file target file, without parameter -s, it will generate a file with the same size as the source file at the location you selected. Whether it is a soft link or a hard link, the file will keep changing synchronously.

The ln command is used to link files or directories. If two or more files or directories are specified at the same time, and the final destination is an existing directory, all previously specified files or directories will be copied to in this directory. If multiple files or directories are specified at the same time, and the final destination is not an existing directory, an error message will appear.

The above is the detailed content of What is the difference between soft links and hard links in linux. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template