Linux Symbolic Link

Source: Internet
Author: User

LN: This command creates a link between files. This operation is actually to specify another name that can be used to access an existing file in the system. For this new file name, we can specify different access permissions for it to control information sharing and security issues. If the link points to a directory, you can use the link to directly enter the directory to be linked without having to create a lot of path names. Besides, even if we delete this link, the original directory will not be damaged.
Format: ln [Option] target directory
There are two types of links: hard link and symbolic link ). When creating a hard link, the linked file and the linked file must be in the same file system, and cannot establish a hard link to the directory. This problem does not exist for symbolic links. By default, ln generates hard links. If the-s option is added to the ln command, a symbolic link is established.

(1) Comparison of the two
Hard links can only reference files in the same file system. It references the physical index (inode) of the file in the file system ). When the original file is moved or deleted, the hard link will not be damaged because it references the physical data of the file rather than the position of the file in the file structure (deleting the link will not delete the source file, deleting source files does not delete links ).
A symbolic link is a pointer pointing to the position of a file in the file system. Symbolic Links can point to files in a remote file system across file systems. The symbolic link only specifies the location of the original file. You must have access to the location of the original file to use the link. If the original file is deleted, all symbolic links pointing to it will be damaged. They direct to a location that does not exist in the file system (deleting a link does not delete the original file, and deleting a source file deletes the link ).

(2) comparison from inode levels

In a Linux File System, files with the same inode value are hard-linked files, that is, different file names may have the same inode, and one inode value may correspond to multiple files.

[Root @ localhost ~] # Ls-Li sun.txt // Note: Attributes of sun.txt;

2408263-RW-r -- 1 Root 29 04-22 sun.txt // Note: This is the property of sun.txt;

[Root @ localhost ~] # Ln sun.txt sun002.txt // note: we use ln to create sun.txt's hard chain file sun002.txt

[Root @ localhost ~] # Ls-Li Sun * // note: we have two columns: sun.txt and sun002.txt.

2408263-RW-r -- 2 root Root 29 04-22 21:02 sun002.txt

2408263-RW-r -- 2 root Root 29 04-22 21:02 sun.txt

We can see that when sun.txthas not created a hard chain file sun002.txt, the number of links is 1 (that is, the value after-RW-r --). After the hard link sun002.txt is created, the value is 2. In other words, every time we create a new hard link file for sun.txt, the number of hard links increases by 1. The inode value is also the same.

We can create a soft link to see:

[Root @ localhost ~] # Ls-Li linuxsir001.txt

2408274-RW-r -- 1 Root 29 04-22 21:53 linuxsir001.txt

[Root @ localhost ~] # Ln-s linuxsir001.txt linuxsir002.txt

[Root @ localhost ~] # Ls-Li linuxsir001.txt linuxsir002.txt

2408274-RW-r -- 1 Root 29 04-22 21:53 linuxsir001.txt

2408795 lrwxrwxrwx 1 Root 15 04-22 linuxsir002.txt-> linuxsir001.txt

The nodes of the two files are different. The numbers of hard links are the same. The numbers of hard links are the same. We also found that there is a mark after linuxsir002.txt->, and linuxsir002.txt is the soft link file of linuxsir001.txt.

 

 

 

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/wangdeng1314/archive/2009/06/10/4254132.aspx

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.