Detailed explanation of ln commands in CentOS

Source: Internet
Author: User
Ln name: ln-makelinksbetweenfiles a brief description of the function of creating connections between files: there is a so-called link in the linxu system. There are two types of links: ========================================================== ========================================== differences between soft links: for a file, there is a unique index point (inode) corresponding to it. Soft link: also known as ln

Name: Ln-make links between files create connections between files

Function description:There is a so-called link in the linxu system. There are two types of links:

========================================================== ============================================

Differences between hard link and soft link:

For a file, there is a unique index point (inode) corresponding to it.

Soft link: a symbolic link is used to generate a new file. the file content only records the path of the file to be connected. A soft link is just a file that records the file path. Therefore, if the source file is deleted, the soft link file still exists.

Hard link: a hard link opens a new directory item for the file. the hard link is equivalent to the original name of the file. in Linux, they are equivalent. All point to the same physical address. In layman's terms, for example, if one item is put in the cabinet and claimed by one person, a hard link is created later, which is equivalent to actually claiming by another person. To clear the cabinet, both parties must agree at the same time. The soft connection is equivalent to a tag, and the cabinet is cleared without the tag consent. Then the directory cannot create a hard link? When creating a hard link, the deletion of a file must be on a unique link at the same index point. Therefore, the hard link ensures that the file is deleted by mistake. That is to say, only when all hard links (including source files) in the physical path are deleted will the connection between the file data block and the Directory be released. Hard links can only be created on the same file system.

========================================================== ============================================

Parameters:

-B. delete and overwrite the previously established connection.

-When the f link is closed, the files with the same name as The dist will be deleted first.
-D allow system administrators to hard link their directories

-I interaction mode. if a file exists, the system prompts the user to overwrite the file.

-N indicates the symbolic link as a general directory.

-S soft link (symbolic link)

-V: detailed handling process

Instance:

1) number of links after creating soft and hard links


You can find that the number of links to the source file does not increase because the soft link is an independent file. When you create a hard link, the number of links to both the source file and the linked file increases, because both point to the same inode. The number of links is actually the number of links to an inode. soft links are new inode files, so they are only 1 at the beginning. The created directory is initial and has


2) after creating a soft link, delete the source file and recreate the source file.

[Root @ bogon ~] # Ll

-Rw-r -- 2 root 17 Apr 26 00:40 1.log

-Rw-r -- 2 root 17 Apr 26 00:40 log

Lrwxrwxrwx 1 root 5 Apr 26 00:20 log1-> 1.log

[Root @ bogon ~] # Rm 1.log

Rm: remove regular file '1. log '? Y

[Root @ bogon ~] # Ll

-Rw-r -- 1 root 17 Apr 26 log

Lrwxrwxrwx 1 root 5 Apr 26 00:20 log1-> 1.log

[Root @ bogon ~] # Echo "this new file"> 1.log

[Root @ bogon ~] # Ll

-Rw-r -- 1 root 14 Apr 26 00:41 1.log

-Rw-r -- 1 root 17 Apr 26 log

Lrwxrwxrwx 1 root 5 Apr 26 00:20 log1-> 1.log

[Root @ bogon ~] # Cat log1

This new file

[Root @ bogon ~] # Cat log

This is old file

Note:

1. after the source file is deleted, the hard link file is not affected. the soft link file is continuously flashing in the centos system, prompting that the source file does not exist.

2. after the source file is re-built, the soft link does not flash, indicating that the link is successful and the linked file system is found. after reconstruction, the hard link file is not affected by the source file, the content of the source file before deletion is retained, indicating that the hard link is invalid.

After a soft connection is created, the permission becomes lrwxrwxrwx. which [U2] is the specific permission?

[Test @ bogontmp] $ cat 1.log

Cat: 1.log: Permission denied


3) create a connection file

Ln-s source file target file soft link

Ln source file target file hard link


Directory Links

The initial number of links in the directory is 2. when a new sub-folder is created under the Directory, the number of connections is increased by 1.

Permission issues for soft connections

Soft links are only a path record, so the actual permission should be the permission of the source file. after all, the inode of the source file is the place where the file read permission is recorded. Tested and verified.


---------------------------- Subsequent self-summary ----------------------------------------

Ln is also commonly used to create connections, mainly to create soft and hard connections. It should be a basic command, and its functions are relatively less complex.


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.