The difference between hard links for Linux soft links

Source: Internet
Author: User

LN is another very important command in Linux, Its function is to create a synchronized link for a file in another location. When we need to use the same file in different directories, we don't need to put a file in every required directory, we just put the file in a fixed directory, and then The other directory uses the ln command to link it so that it does not have to use disk space repeatedly.

1. Command format:
ln [parameter] [source file or directory] [destination file or directory]

2. Command function:
Linux file system, there is so-called link, we can consider it as the alias of the file, and the link can be divided into two: Hard link and soft link (symbolic link), hard link means that a file can have multiple names, The soft link is the way to produce a special file, the contents of which is pointing to the location of another file. Hard links exist in the same file system, but soft links can span different file systems.

Soft Links:
1. Soft links, in the form of a path exists. Similar to shortcuts in the Windows operating system
2. Soft links can cross file system, hard links can not
3. Soft links can link to a nonexistent file name
4. Soft links can be linked to the directory

Hard Links:
1. Hard link, in the form of a copy of the file. But does not occupy the actual space.
2. Do not allow the creation of hard links to the directory
3. Hard links can only be created in the same file system
Here are two points to note:
First, the LN command maintains the synchronization of each linked file, meaning that no matter where you change it, the other files will change the same.
Second, Ln's links are soft links and hard links two, soft link is the ln–s source file destination file, it will only generate a file in your selected location image, will not occupy disk space, hard link ln source file destination file, no parameter-s, It will generate a file of the same size as the source file in the location you selected, whether it is a soft link or a hard link, and the file keeps changing synchronously.
The ln instruction is used in a linked file or directory, such as specifying more than two files or directories at the same time, and the final destination is a directory that already exists, and all of the previously specified files or directories are copied to the directory. If you specify multiple files or directories at the same time, and the final destination is not an existing directory, an error message appears.

3. Command parameters:
Necessary parameters:
-B Delete, overwrite previously established link
-D allows super users to make hard links to directories
-F Force Execution
-I interactive mode, file presence prompts the user whether to overwrite
-N treats symbolic links as generic directories
-S soft link (symbolic link)
-V displays detailed processing procedures

Select parameters:
-S "-s< tail backup string >" or "--suffix=< tail backup string >"
-V "-v< backup method >" or "--version-control=< backup method >"
--HELP Display Help information
--version displaying version information

4. Usage examples:
Example 1: Create a soft link to a file
In order to more carefully explain the relative path problem of creating soft links, we first create a few deep-point folders

1 mkdir -p/app/a{1.. 3} /b{c. F}

The approximate hierarchy can be seen, the app directory and the ETC directory are all under the root directory

Let's say we give the root directory a soft link to the location of/magedu/zd/2g/login.bat in the root directory, so the soft link should be APP/A1/BC.

1 Ln -S. /.. /.. /magedu/zd/2g/login.bat/app/a1/bc/softlink1

A lot of classmates confused how to write the relative path of the target path, the relative path to the file or folder is based on the folder where the soft link is located , relative to how the file indicates to the system the path he is going to take.

In this example, the soft link in the directory is the root directory of APP/A1/BC, then this BC folder is the base point folder, from here up a layer back to A1, syntax is. /, go up one level to the app folder and one more. /, because magedu is in the root directory, it also needs a layer to return to the root directory that is three. /, the root directory knows how to express, the next step is to paste the absolute path to the source file address. Multi-level catalogs are set up, so the shallow catalog is needless to say.

How to see if there is a problem with the link you have established, enter into the soft link directory ls view, the soft link name of the file is light blue.

The difference between hard links for Linux soft links

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.