Ln soft link and hard link

Source: Internet
Author: User

Address: http://www.dutor.net/index.php/2010/07/symbol-hard-links/

There are two types of links in Linux/Unix: hard links and soft links, which are created by ln commands.

Ln-S/home/M/. vimrc/Media/elements/115/vimrc

Soft link

The soft link is created using the-s option of the ln command:

1
Ln -S SourceFilename# Create a soft link target (Destination Address) for the source file)

Soft links are similar to shortcuts in Windows. The path of the source file is saved internally. The path can be relative or absolute:

123456
Dutor @ Dutor-desktop :~ $ Ln   -S Gvim. tgz gvimdutor @ Dutor-desktop :~ $ Ln   -S  / Home / Dutor / Gvim. tgz gvim2dutor @ Dutor-desktop :~ $ Ll gvim *   # Alias LL = 'LS-l' Lrwxrwxrwx 1 Dutor 8   2010 -07-01 20 : 32 Gvim-> Gvim. tgzlrwxrwxrwx 1 Dutor 20   2010 -07-01 20 : 33 Gvim2- >   / Home / Dutor / Gvim. tgz -RW-r --   1 Dutor 8.5 m2010 -06- 29   23 : 06 gvim. tgz

Soft links are widely used.
When multiple files share the same large file in the file system, you can use soft links to avoid creating multiple copies.
When maintaining the version of a dynamic library file, use soft links. After upgrading the library file, you only need to modify the soft link source file and useProgramIt does not need to be modified.

Hard Link

You can create a hard link by using the ln command without any options:

 1 
  ln   source  Target # create a hard link target for the source file  

After a hard link is created, there is no primary or secondary distinction between the linked file and the source file. They are all associated with the same inode in the file system, that is, they have the same inode Number:

1234
 dutor @ dutor-desktop :~ $  ln  gvim. tgz gvimdutor @ dutor-desktop :~ $ Ll -I  gvim  *   1048032  -RW-r --   2  dutor 8.5 m  2010 -06- 29   23 : 06 gvim # 3rd fields represent the number of links to the file   1048032  -RW-r --   2  dutor 8.5 m  2010 -06- 29   23 : 06 gvim. tgz 

Therefore, the system does not allow users to create hardware links for directories. Otherwise, the directory tree will no longer have a directed acyclic graph. The system can "create" a hard link for the directory (the system knows what it is doing, but does not know what the user will do. and .. point to the current directory and the parent directory respectively. Therefore, the number of links in each directory must be at least 2.

In addition, since the implementation of hard links depends on a specific file system, cross-file systems are not allowed. Soft links are path-based. Therefore, you can create soft links as long as they are files or directories mounted to the system directory tree.

End

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.