2017-7-18-Daily blog-About soft links and hard links under Linux. doc

Source: Internet
Author: User

lnCommand
This command creates a link between the files. This kind of operation is actually to give a file that already exists in the system to specify another name that can be used to access it. For this new file name, we can specify different access rights to control the sharing and security of the information. if the link is to a directory, the user can use the link to go directly to the linked directory without having to hit a lot of path names. Moreover, even if we delete this link, it will not destroy the original directory.
Syntax:ln [Options] Target[Link Name]
  ln [Options] Target directory
There are two types of links, one called Hard links (Hard Link), another is called Symbolic link (Symbolic Link). When a hard link is established, the linked file and the linked file must be in the same file system, and a hard link to the directory cannot be established. For symbolic links, there is no such problem. By default,LNgenerate a hard link.
in the case of a hard link, the parameters in the“Target"be linked to[Link Name]. If[Link Name]is a directory name under which the system will establish one or more"Target"A linked file with the same name, the link file and the contents of the linked file are identical. If[Link Name]as a file, the user will be told that the file already exists and is not linked. If you have specified more than one"Target"parameter, the last parameter must be a directory.
If you givelnCommand plus-Soption, a symbolic link is established. if[Link Name]already exists but is not a directory, will not do the link. [Link Name]can be any file name (which can contain a path), or it can be a directory, and allow it to be"Target"is not in the same file system. If[Link Name]is an existing directory in which the system will establish one or more"Target"file with the same name, this new file is actually pointing to the original"Target"the symbolic link file.

eg

Ln-s Source Dist # establishing a soft connection

N Source Dist # to establish a hard connection

Soft link is actually just a piece of text, which contains the name of the file it points to, the system sees the soft link automatically jumps to the corresponding file location for processing; instead, a hard link opens a new directory entry for the file, and the hard link and the original name of the file are equal, and in Linux it seems equivalent. For this reason, a hard link cannot connect files on two different file systems.
Soft connections are similar to shortcuts under Windows

As for a hard connection, for example, you put dir1/file1 hard connect to Span style= "Font-family:calibri" >dir2/file2,   is in Dir2 dir1/file1 image file file2 file1 .
Soft joins and hard joins can be understood as:
Hard connect is like a file with multiple filenames,

A soft connection is the creation of a new file ( the content of this file , In fact, is to link the original file path information ) , this file points to the location of another file,

Hard connections must be in the same file system, and soft connections can cross file systems
Hard Connect : Both the source file name and the link file name point to the same physical address, the directory can not have a hard connection, the file has only one copy on the disk, can save hard disk space, because the deletion of the file to the same index node belonging to a unique connection can be successful, so you can prevent unnecessary accidental deletion of soft connections (symbolic connections) with ln-s command to create a symbolic connection of a file, a symbolic connection is a special file of Linux , as a file, its data is the path name of the file it connects, similar to the hardware,* * * You can delete the original file and the connection file still exists.

links are available in two ways, soft links and hard links.
  1Soft Link File
soft links are also called Symbolic links,This file contains the path name of another file .. can be any file or directory that can link files from different file systems.
**********linked files can even link nonexistent files, which produces what is commonly called'Broken Chain'the problem( or"phenomena'), linked files can even be looped to link themselves. Similar to recursion in a programming language.
withLn-scommand can generate a soft connection, as follows:
  [Email protected] test]# ln-s source_file softlink_file
When you read or write to the symbol file, the system automatically converts the operation to the source file, but when you delete the linked file, the system simply deletes the linked file without deleting the source file itself.
  2Hard Link File
  Info LNcommand tells you thata hard link is another name for a file that already exists(A ' Hard link ' was another name for a existing file), which is somewhat confusing. The hard-connect command is
  ln-d Existfile NewFile
There are two restrictions on hard-link files
  1), do not allow to create hard links to the directory;
  2), you can create a hard link only between files in the same file system.
  ***********when you read and write to a hard-link file, the result is the same as a soft link. But if we delete the source file of the hard-link file, the hard-link file still exists, and the content of the wish is preserved.
***********at this point, the system will"Forget"It was once a hard-link file. And treat him like a regular file.
two the difference between the two
A hard join refers to a connection made through an index node. -in theLinuxFile system, files that are saved in a disk partition, regardless of type, assign a number to it, called the index node number(Inode number).
in theLinux, multiple file names point to the same index node that exists. In general, this connection is a hard connection. *******The purpose of a hard connection is to allow a file to have more than one valid pathname so that the user can establish a hard connection to an important
file,to prevent"Accidental deletion"the function. The reason for this is as above, because there is more than one connection to the index node that should be the directory. Deleting only one connection does not affect the index node itself and other connections, only if the last
The connection to the file's data block and directory will be released when the connection is deleted. In other words, the file is actually deleted.
the soft link file is somewhat similar toWindowsthe shortcut. It is actually a kind of special file. In a symbolic connection, a file is actually a text file that contains location information for another file.
three Personal Experience
A soft link is another file that can be understood as a pointer,******action on this file except the deletion is directly to the actual point of the file, because it is a real file, so occupy disk space
A hard link can be considered not a file, it is just an alias of the actual file, its role is to prevent the real file is mistakenly manipulated, to a file after the establishment of a hard link, they alias each other, delete any of them,
this usesRmthe command only deletes the alias, and the actual file is not deleted. Only the number of links is0The original file is deleted

2017-7-18-Daily blog-About soft links and hard links under Linux. doc

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.