Linux to establish the soft Link ln command usage method

Source: Internet
Author: User
Tags symlink

Soft links under Linux are similar to shortcuts under Windows

Ln-s A B is the source file, B is the link file name, its function is when entering the B directory, actually is the link into a directory

As the above example, when we execute the command cd/gamestat/, we actually enter the/home/gamestat/
It is noteworthy that when executing the command, it should be a directory has been established, directory B has not been established. The first thing I did was set up the B directory, and it turned out to be wrong.

To delete a soft link:

RM-RF B Note not RM-RF

Establish a hard link

ln a b

Example: Ln-s/home/gamestat/gamestat

First, create a soft link, as long as you add the option –s after Ln, here's an example

[Root@rekfan.com test]# Ls-il
Total 0
1491138-rw-r–r–1 root root 07-14 14:17 file1
1491139-rw-r–r–2 root root 0 07-14 14:17 file2
1491139-rw-r–r–2 root root 0 07-14 14:17 File2hand

[root@rekfan.com test]# ln-s file1 file1soft
[Root@rekfan.com test]# Ls-il
Total 0
1491138-rw-r–r–1 root root 07-14 14:17 file1
1491140 lrwxrwxrwx 1 root 5 07-14 14:24 file1soft-> file1
1491139-rw-r–r–2 root root 0 07-14 14:17 file2
1491139-rw-r–r–2 root root 0 07-14 14:17 File2hand

From the results of the link above can be seen to soft links and hard links, the difference is not only in the concept, in the implementation is also different. Difference: Hard Link Original file & Link file common an inode number, stating that they are the same file, and that the soft link original file and link file have different inode numbers, indicating that they are two different files; the soft links on the file properties explicitly write the link file, and the hard link is not written, Because in essence the hard link file and the original file are completely equal; The number of links is different, the number of links to soft links does not increase; File size is not the same, hard link file display size is the same as the original file, which is emphasized, because it is equivalent, and here the soft link display size and the original file is different, The file1 size is 48B, and the File1soft is 5B, and the 5 is actually the size of "file1".

In short, creating a soft link creates a new file. When you access the linked file, the system finds that he is a linked file that reads the linked file and finds the file that you really want to access.
The establishment of soft links between different systems, the directory to establish links, here is not an example, the reader can try for themselves, I am also in the continuous practice of learning.
Of course, soft links also have the disadvantages of hard links, because the link file contains the original file path information, so when the original file from a directory moved to other directories, and then access to the link file, the system can not find ~ ~, and hard links do not have this flaw, you want to move on how to move (hehe) And it wants the system to allocate additional space for creating new indexing nodes and for saving the path of the original file.

Add: You can see the link file through Symlink, you can learn it with man symlink.

Third, delete the link

There is a deletion of the creation

RM-RF symbolic_name attention is not RM-RF symbolic_name/

[Root@rekfan.com test]# Ls-il
Total 0
1491138-rw-r–r–1 root root 0 07-14 14:17 file1
1491140 lrwxrwxrwx 1 root 5 07-14 14:24 file1soft-> file1
1491139-rw-r–r–2 root root 0 07-14 14:17 file2
1491139-rw-r–r–2 root root 0 07-14 14:17 File2hand
[Root@rekfan.com test]# RM-RF File1soft
[Root@rekfan.com test]# Ls-il
Total 0
1491138-rw-r–r–1 root root 0 07-14 14:17 file1
1491139-rw-r–r–2 root root 0 07-14 14:17 file2
1491139-rw-r–r–2 root root 0 07-14 14:17 File2hand
[Root@rekfan.com test]#

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.