Linux Create connection command ln-s soft link

Source: Internet
Author: User

This is a very important command in Linux, please be familiar with it. Its function is to create a link to a file in another location, the most common parameter of this command is-s,
The specific usage is: Ln-s source file Destination file.
when we need to use the same file in different directories, we do not need to put a file in each required directory, we just put the file in a fixed directory, and then in the other directory with the ln command link it can, do not have to repeatedly occupy disk space. Example: Ln-s/bin/less/usr/local/bin/less
- S is the meaning of the Code name (symbolic).
here are two points to note: first, the LN command will maintain the synchronization of each linked file, that is, no matter where you change, the other files will change the same; second, ln links and soft links and hard links two, soft link is ln-s * *, It will only generate a mirror image of the file in the location you selected, not disk space, hard link ln * *, no parameter-s, it will generate a file in your chosen location with the same size as the source file, whether it is a soft link or a hard link, the file will remain in sync.


whether a hard link or a soft link will not copy the original file, it will only occupy a very small amount of disk space.
-F: Delete the file with the Dist file name at the end of the link
-D: Allow system managers to hard-link their own directories
-I: Ask before deleting the file with the Dist file name
- N: When making a soft link, treat the dist as a generic file
-S: Soft junction (symbolic Link)
- V: Displays the file name before the link
-B: Files that are overwritten or deleted at the time of the link are backed up
-S SUFFIX: Add the backed up files with SUFFIX tails
-V Method: Specify how the backup should be
--help: Show Auxiliary Instructions
--version: Display version

"hard Connect"
Hard connect refers to connecting through an index node. In a Linux file system, a file saved in a disk partition, regardless of the type, assigns a number to it, called the index node number (Inode index). In Linux, multiple file names point to the same index node that exists. In general, this connection is a hard connection. The purpose of a hard connection is to allow a file to have multiple valid pathname, so that users can establish a hard connection to important files to prevent "accidental deletion" of the function. The reason for this is as above, because there is more than one connection to the index node that should be the directory. Deleting only one connection does not affect the index node itself and other connections, and the connection to the file's data block and directory will be released only if the last connection is deleted. That is, the condition that the file is actually deleted is that all the hard connection files associated with it are deleted.

"Soft Connect"
Another connection is called a symbolic connection (symbolic link), also known as a soft connection. A soft-link file has a shortcut similar to Windows. It's actually a special file. In a symbolic connection, a file is actually a text file that contains location information for another file.

2. Deepen understanding through experimentation
[email protected]]$ vi test.log #创建一个测试文件f1
[email protected]]$ ln test.log test1.log #创建f1的一个硬连接文件test1. Log
[email protected]]$ ln-s test.log test2.log #创建f1的一个符号连接文件test2. Log
[[Email protected]]$ ls-li #-I parameter displays inode node information for a file

The difference between the two links:   

      hard-Link file has two restrictions   
 1), do not allow the creation of hard links to the directory;
 2), links can only be created between files in the same file system, and only Superuser has the ability to establish hard-link permissions.   
      The result is the same as a soft link when reading and deleting a hard-link file. But if we delete the source file of the hard-link file, hard-link file still exists, and retains the content of the wish.

At this point, the system "forgot" it was once a hard link file. And treat him like a regular file.

so we can understand this: a hard connection is a connection made through an index node, which allows a file to have multiple valid path name, can achieve the role of the accidental deletion.

The reason for this is because the corresponding file's index node has more than one connection. Deleting only one connection does not affect the index node itself and other

Connection will be released only if the last connection is deleted and the file's data block and directory are connected. The file will not be really deleted.

           Note: Keep a file in a disk partition regardless of what type assigns it a number, < Span style= "MARGIN:0PX;PADDING:0PX;LINE-HEIGHT:1.5;FONT-SIZE:16PX;" > is called the index node number (Inode index is the i node).            

Soft links do not have a hard link above the two limitations, so now more widely used, it has greater flexibility, even can be across different machines, different networks to link files. However, the disadvantage of soft link is: Because the link file contains the path information of the original file, so when the original file from one directory to another directory, and then access the linked file, the system will not be found, and the hard link does not have this flaw, you want to move how to move And it wants the system to allocate additional space for creating a new index node and saving the path to the original file.

This article originates from http://www.cnblogs.com/kex1n/p/5193826.html

This article is from the "Dream to Reality" blog, please be sure to keep this source http://lookingdream.blog.51cto.com/5177800/1909967

Linux Create connection command ln-s soft link

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.