Linux soft Connect "turn"

Source: Internet
Author: User

Https://www.cnblogs.com/kex1n/p/5193826.html
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 a different directory, we do not need to put in each required directory must be the same file, we just put in a fixed directory, the file, and then in other directories with the ln command link, it can, do not have to repeatedly occupy disk space. For example: Ln-s/bin/less/usr/local/bin/less 
-S is the meaning of the codename (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 does not copy the original file, it only consumes a very small amount of disk space.
-F: Link to the file with the same file name Dist deleted
-D: Allow the System Manager to hard-link their own directory
-I: When deleting the file with the dist file with the first query
-N: When the soft link, the dist as a normal file Case
-S: Soft link (symbolic link)
-V: Display its file name before linking
-B: Files that will be overwritten or deleted at the end of the link
-s SUFFIX: Add the backed up files to the SUFFIX br>-V Method: Specify how the Backup
--help: Show Secondary description
--version: Show version

"Hard Connect"
A hard connection is a connection that is made 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 types of links:

There are two restrictions on hard-link files
1), do not allow to create 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.
When you read and write to a hard-link file, the result is the same as a soft link. But if we delete the source file of the hard-link file, the hard-link file still exists, and the content of the wish is preserved.

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 more than one valid pathname, which can be used to delete the error.

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: Files that exist on a disk partition are assigned a number, called the Index node number (Inode index, the I node), regardless of the type.

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.

Delete:

#mkdir Test_chk

#touch Test_chk/test.txt

#vim Test_chk/test.txt (This step can write something in this test.txt)

Let's create a soft link to the Test_chk directory

#ln-S Test_chk test_chk_ln

Soft link created well, let's see how to delete it

Correct deletion method (remove soft link, but do not delete actual data)

Rm-rf./test_chk_ln

How to delete the error

Rm-rf./test_chk_ln/(This will remove the contents of the original Test_chk)

Linux soft Connect "turn"

Related Article

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.