Linux Hard link Soft Connect

Source: Internet
Author: User

Scenario Description:

Sometimes under Linux we have a big project with absolute path related, and now want to see through the Eclipse source code and modify the source code, then the problem is:

1. If we copy the source code into the Eclipse project, it is cumbersome to manually copy the file to the original project directory that can be run after it has been modified.

2. If you directly re-deploy the source under Eclipse, you will have to modify a lot of paths in order for this project to run properly under the new path.

Workaround: Create a soft connection ln-s/xxxxxx/test Workspace/myproject


Questions:

What is a soft link? What's the difference between a hard link?


The following paragraph from the Baidu Encyclopedia:

The difference between a hard link and a soft link


In a Linux file system, files that are saved in a disk partition, regardless of the type, assign a number to it, called the inode number of the index node. A soft connection, in fact, is the creation of a new file, which is specifically used to point to other files (that is, the shortcut under Windows, the file is very close to the meaning). The soft link produces a new file, but the purpose of this file is to point to a file, delete the soft connection file, it is equal to not need this connection, and the original existence of the entity original file does not have any relationship, but delete the original file, then the corresponding soft connection is not available (cat that soft link file, then prompt " No this file or directory ")
A hard connection does not create an inode, he only adds 1 to the original Inode link Count field in the file, and therefore hard links are not allowed to span the file system. Instead, the soft link will re-establish an inode, although the structure of the inode is not the same as the rest, he is just a string of information indicating the source file. Once the source file is deleted, the soft connection becomes meaningless. When a hard link is deleted, the system call checks the Inode link count value, and if he is greater than or equal to 1, the inode is not recycled. Therefore, the contents of the file are not deleted.
Hard links actually create an alias for the file, and the link file and the original file are actually the same file. Can be viewed through ls-i, the inode number of these two files is the same, indicating that they are the same file, and the soft link is established a point, that is, the content of the linked file is a pointer to the original file, they are two files.
Soft links can cross the file system, hard links can not, soft links can be a nonexistent file name (filename) Link (of course, if you vi this soft link file, Linux will automatically create a file named filename), hard links can not (its file must exist, Inode must be present), soft links can be connected to the directory, hard links are not available.Two kinds of links can be created by command Ln. The default for LN is to create a hard link. Use the-s switch to create a soft link.


Say it simple.

1. Modify the soft connection or hard link will cause the source file changes, can achieve the purpose of synchronization

2. Deleting a soft link or a hard-link file will not erase the original file.

3. Deleting the source file will invalidate the soft connection, and the hard-link file is still intact.

4. It is important to establish a soft connection to the directory but not to establish a hard link, only to establish a hard link to the file, which is also the reason for the construction of the project to establish a link why choose a soft connection


Linux Hard link Soft Connect

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.