Differences between soft links and hard links in Linux

Source: Internet
Author: User

A link is a way to establish a connection between a shared file and several directory items of the users who access it. Linux contains two types of links: hard link and soft link. Soft link is also called symbolic link ). A hard link can be considered as a file with two file names, while a soft link is a new link file created by the system, which points to the file to which it refers.

1. Usage:
Ln [Option] source_file dist_file
-F: When the file is created, the same file name will be deleted.
-I ask before deletion.
Ln-s abc cde establishes a soft connection of ABC
Ln abc cde establishes a hard connection to ABC,


2. Differences between soft links and hard links:

First, you need to understand that in Linux, the kernel assigns an inode (index node) to each newly created file, and each file has a unique inode number. The file attributes are stored in the index node. when accessing the file, the index node is copied to the inner to implement fast file access. Inode is the data structure used within UNIX to describe file features. we usually call I a file index node (information node ). the I node contains most important information about the file, including the address of the file data block on the disk. each I node has its own flag number, which is called the document sequence number. I node Information 1. file Type 2. file owner relationship 3. file Access permission 4. file timestamp.

1) hard link

A hard link is a pointer pointing to a file index node, and the system does not re-allocate inode for it. You can use the ln command to create a hard link. Syntax:

Ln [Options] existingfile newfile
Ln [Options] existingfile-List Directory

Usage: the first method is to create a hard link for "existingfile" and the file name is "newfile ". Type 2: Create a hard link with the same name for all files contained in "existingfile-list" in the "directory" directory. Commonly used [Options]-F creates a link regardless of whether "newfile" exists or not. -N if "newfile" already exists, no link is created.

2) Soft link (symbolic link)

Soft links overcome hard links without any restrictions on the file system. Any user can create symbolic links pointing to directories. As a result, it is more widely used. It has more flexibility and can even link files across different machines and networks. Soft links can be used to link a non-existent file name, and soft links can also be used to link directories.
To create a soft link, add the option-s after ln.

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.