Introduction and experimentation of hard links and soft links in Linux

Source: Internet
Author: User

In Linux, links are broken down into hard links and soft links, and soft links are also known as symbolic links (symbolic link), which, without any parameters, creates a hard link using the ln command.

Hard link: A hard link is linked by an index node. in a Linux file system, files that are stored in a disk partition, regardless of the type of file, will be assigned a number, which is called the Index node number (inode index) or inode. Multiple file names point to the same index node (Inode), which is generally referred to as a hard link. One of the functions of a hard link is to allow a file to have multiple valid pathname names. This allows users to establish hard links to important files to prevent "accidental deletion" of source data. The Create hard-link source file must exist. and a hard link can only establish a hard link to a file, not a directory. A hard link is the equivalent of another entry in a file. Use the LN command to create directly.

Soft Links: Also known as symbolic links. Similar to a shortcut in Windows, it is actually a special file. in a soft link. A soft link file is actually a text file that contains the location information content of a soft link to another file, so you can quickly navigate to the original file entity that the soft link points to by accessing the shortcut. Use Ln-s.

Here are a few experiments:

First we create the guixian001 file in the home directory of the normal user guixian001. Using VI to add hello! I am guixian001! content.

[email protected] ~]$ Touch guixian001 [[email protected] ~]$ VI guixian001 #添加内容Hello! I am guixian001!

Create guixian001 hard-link file guixian001_hard_link, and soft-link file guixian001_soft_link. Use Ls-li to view.

650) this.width=650; "title=" qq20150515085224.jpg "src=" http://s3.51cto.com/wyfs02/M02/6C/DF/ Wkiol1vvrrxgxdp0aakuyggjhge895.jpg "alt=" Wkiol1vvrrxgxdp0aakuyggjhge895.jpg "/>

It is important to note that we can see the same number of guixian001 and Guixian001_hard_link, and this is what we just said about the Inode node. That is, the hard links and source files are the same as the inode. In the third column you can see the number 2, which means the file is linked 2 times (guixian001 and guixian001_hard_link add up 2 times).

Link Summary:

⒈ Delete Soft link guixian001_soft_link, the actual soft link is equivalent to a shortcut file, so remove the soft link to guixian001, and Guixian001_hard_link has no effect.

⒉ Delete Hard link guixian001_hard_link, has no effect on guixian001,guixian001_soft_link.

⒊ Delete the original file guixian001, the hard link has no effect, in fact, the file has not really deleted (also stored in the hard disk), the soft link will fail (the target is not gone). As follows:

650) this.width=650; "title=" qq20150515090341.jpg "src=" http://s3.51cto.com/wyfs02/M02/6C/E4/ Wkiom1vvrgraiq6iaaed8zixoxe844.jpg "alt=" Wkiom1vvrgraiq6iaaed8zixoxe844.jpg "/>

⒋ also delete the original file guixian001 and the hard link file Guixian001_hard_link, this file will be really deleted.

References:

1. old boy Linux Tutorial

Author:chenguixian (guixian001)

This article is from the "Operations Note _" blog, please be sure to keep this source http://chenguixian.blog.51cto.com/1646030/1651460

Introduction and experimentation of hard links and soft links in Linux

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.