Linux soft link and hard link

Source: Internet
Author: User

1. linked file
There are two methods for linking: Soft link and hard link.

1. Soft link file

Soft links are also called symbolic links. This file contains the path name of another file. It can be any file or directory that can be linked to files of different file systems.
A linked file can even link a non-existing file, which leads to a problem (or "Symptom") that is commonly called "broken chain". linked files can even link themselves cyclically. SimilarProgramming LanguageRecursion in.
You can use the Ln-s command to generate a soft connection, as shown below:
[Root @ linux236 test] # ln-s source_file softlink_file
When reading or writing a symbolic file, the system automatically converts the operation to an operation on the source file. However, when deleting a linked file, the system only deletes the linked file, instead of deleting the source file.
2. Hard link file
The info ln Command tells you that a hard link is another name of an existing file (a "hard link" is another name for an existing file), which is somewhat confusing. The hard connection command is
Ln-D existfile newfile
There are two restrictions on hard-link files
1) hard links cannot be created for directories;
2) The link can be created only between files in the same file system.
When you perform read/write or delete operations on hard-link files, the results are the same as those of soft-link files. However, if we delete the source file of the hard link file, the hard link file is still stored and the expected content is retained.
At this time, the system "forgot" that it was a hard link file. And regard it as a common file.
The difference between the two

Hard connection refers to the connection through the index node. In a Linux File System, a file stored in a disk partition is assigned with an index node number (inode index) No matter what type it is ).
In Linux, multiple file names direct to the same index node. Generally, this type of connection is hard connection. The purpose of hard connection is to allow a file to have multiple valid path names, so that you can establish a hard connection to an important
File to prevent "accidental deletion. The cause is as described above because there is more than one connection to the index node of the directory. Deleting only one connection does not affect the connection between the index node and other nodes.
After the connection is deleted, the data block and directory connection of the file will be released. That is to say, the object will be deleted.

 

Soft-link files are similar to Windows shortcuts. It is actually a type of special file. In a symbolic connection, a file is actually a text file containing the location information of another file.

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.