Differences between soft links and hard links in Linux

Source: Internet
Author: User

Differences between soft links and hard links in Linux

Ln is another important command in linux. Its function is to create a synchronization link for a file in another location. when we need to use the same file in different directories, we do not need to put a file that must be the same under each required directory. We only need to put it in a fixed directory, put the file, and then use the ln command link in other directories to link it, without occupying disk space repeatedly.

1. Command Format:

Ln [parameter] [source file or directory] [target file or directory]

2. command functions:

In a Linux File System, there is a so-called link. we can regard it as the alias of the file, and there are two types of links: hard link) with symbolic link, a hard link means that a file can have multiple names, while a soft link generates a special file, the content of this file points to another file. Hard links exist in the same file system, but soft links can span different file systems.

Soft link:

1. Soft links exist as paths. Similar to shortcuts in Windows

2. Soft links can be cross-file systems, but hard links cannot.

3. Soft links can be used to link a non-existent file name

4. Soft links can be used to link Directories

Hard link:

1. Hard links exist in the form of file copies. But it does not occupy the actual space.

2. Hard links cannot be created for directories.

3. Hard links can only be created in the same file system

Note the following two points:

First, the ln command will keep the synchronization of each link file. That is to say, other files will change the same no matter which one you have changed;

Second, there are two types of ln links: Soft link and hard link. The soft link is the target file of the ln-s source file. It will only generate an image of the file at the position you selected, it does not occupy disk space. It is hard linked to the target file of the ln source file without the parameter-s. It will generate a file of the same size as the source file at the position you selected, both soft links and hard links are synchronized.

Ln commands are used to link files or directories. For example, if you specify more than two files or directories at the same time, and the final destination is an existing Directory, all the previously specified files or directories will be copied to this directory. If multiple files or directories are specified at the same time and the destination is not an existing Directory, an error message is displayed.

3. command parameters:

Required parameters:

-B: delete the file, overwrite the previously created link.

-D allows the superuser to create hard links to directories.

-F Force Execution

-I interaction mode. If a file exists, the system prompts the user to overwrite the file.

-N indicates the symbolic link as a general directory.

-S soft link (symbolic link)

-V: detailed handling process

Select parameters:

-S "-S <suffix backup string>" or "-suffix = <suffix backup string>"

-V "-V <backup mode>" or "-version-control = <backup mode>"

-Help: displays help information.

-Version: displays version information.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.