Linux Study Notes-ln command (link command)

Source: Internet
Author: User

Linux Study Notes-ln command (link command)

Ln: English name link.

In Linux, there are two special "Files": Soft links and hard links ".

Hard link features:

1) Hard-link files have the same inode nodes and storage block as source files. They can be considered as the same file. 2) It can be identified by I nodes (the same as I nodes ). 3) The linked file and source file must be in the same partition and cannot be cross-partition. 3) hard links cannot be created for directories. (Although the Linux ln Command help description can use "ln-d" to create a hard link to the directory, my actual test is not feasible. I searched for a detailed explanation on the Internet, for more information, see the "special note" at the bottom of the Article ".) 4) modify any file and the content of the other file will change. 5) when the source file is deleted, the hard link file can still be used normally.

Soft link features:

1) soft-link files play the same role as windows shortcuts. 2) the soft link has its own I node and storage block, but the information saved in this data block is the I node and file name information of the source file, and does not save the actual file data content. 3) when you run the "ll" command to view the file, the soft link file is preceded by "lrwxrwxrwx". The first letter "l" indicates that the file is a soft link file, the true permissions of soft-link files depend on the permissions of the source files. 4) modify any file and the content of the other file will change. 5) when the source file is deleted, the soft link file cannot be used.

1. Command Format:

Ln [Option] source file or directory target file or directory

2. Common options:

"Ln-B" if a file with the same name already exists in the target directory, back up the file with the same name before overwriting. "ln-f" if a file with the same name already exists in the target directory, no prompt is required, directly overwrite "ln-I" for human-computer interaction. If a file with the same name already exists in the target directory, the system prompts whether to overwrite "ln-n" to treat the soft link as a general directory (note: in this example, I will explain in detail) "ln-s" to create a soft link "ln-v" to show detailed steps of the operation. (V indicates verbose)

3. Common examples:

1) create a hard link file.

2) create a soft link file.

3) create a hard link file. If a file with the same name already exists in the target directory, back up the file before overwriting.

<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4NCjxwcmUgY2xhc3M9 "brush: SQL;"> 4) create a soft link for the directory.

5) "ln-n" command instance description.

6) failed instance Creation

Note:

1) when creating a soft link, if the soft link file is not in the same directory as the source file, the source file address must be an absolute path; otherwise, the created soft link cannot be used. 2) hard links cannot be created for files. "There are two restrictions on hard connections in linux: they cannot span the file system and do not allow common users to make hard connections to directories. As for the first limit, it is easy to understand, and the second limit is not so easy to understand. Using the ls-l command on any directory, we can see that the number of connections is at least 2, which also indicates that there is a hard connection in the system, the command ln-d can also allow the Super User to make a hard connection to the directory, which means that the system restricts the hard connection to the directory, it is not logically not allowed or technically unavailable. Why is the operating system restricted? If a hard connection to the directory is introduced, loops may be introduced in the directory, and the system will be stuck in an infinite loop during directory traversal. Maybe you will say that the symbolic connection can also introduce a loop, so why not restrict the symbolic connection of the directory? In linux, each file (directory is also a file) corresponds to an inode structure. The inode data structure contains the file type (directory, common file, information, that is, the operating system can determine the symbolic connection when traversing the directory, now that you can determine the symbolic connection, you can take some measures to prevent a large loop. The system stops traversing after eight consecutive symbolic connections, this is why directory symbolic connections do not enter an endless loop. However, due to the data structure and algorithm restrictions in the operating system, hard connection cannot prevent such an endless loop. "(This answer is found online. Because the source and original author information of the article cannot be found, the original author information cannot be identified. If you have any author, please contact me quickly, I will promptly Add the author information. Thank you)

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.