Linux Command: ln usage

Source: Internet
Author: User

 

Command: ln usage

Command name: ln

Permission: All Users

Usage: ln [options] source dist, where the option format is:

[-BdfinsvF] [-S backup-suffix] [-V {numbered, existing, simple}]

[-- Help] [-- version] [--]

Note: there is a so-called link in the Linux/Unix File System. we can regard it as the alias of the file, and the link can be divided into two types: hard link) symbolic link means that a file can have multiple names, while a soft link generates a special file, the content of this file points to another file. Hard links exist in the same file system, but soft links can span different file systems.

Ln source dist is used to generate a connection (dist) to the source. As for hard link or soft link, it is determined by the parameter.

No matter whether it is a hard link or soft link, it will not copy the original file, it will only occupy a very small amount of disk space.

Parameter format:

-F: when the link is closed, the file with the same name as dist is deleted first.

-D: allows system administrators to hard link their directories.

-I: When deleting an archive with the same name as dist, first ask

-N: dist is considered as a normal file During Soft link.

-S: symbolic link)

-V: display the file name before the link

-B: Back up the files that will be overwritten or deleted during the link.

-S suffix: adds the backup file to the end of SUFFIX.

-V method: Specifies the backup METHOD.

-- Help: displays auxiliary instructions

-- Version: displays the version.

Example:

Generate a symbolic link: zz

Ln-s yy zz

Generate a hard link: zz

Ln yy xx

 

 

 

Ln command usage (F)

Ln is a very important command in linux. Its function is to create a non-same link for a file in another location. The most common parameter of this command is-s. The specific usage is the target file of the ln-s source file.

When we need to use the same file in different directories, we do not need to put a file that must be the same under each required directory. We only need to put it in a fixed directory, put the file, and then use the ln command link in other directories to link it, without occupying disk space repeatedly. Example: ln-s/bin/less/usr/local/bin/less

 

-S indicates the symbol (symbolic.

Note the following two points:

 

First, the ln command will keep the synchronization of each link file. That is to say, other files will change the same no matter which one you have changed;

 

Second, ln links are divided into two types: symbolic links and hard links. The symbolic links are ln-s ****, it will only generate a file image at the position you selected, and will not occupy disk space, hard link ln *****, no parameter-s, it will generate a file with the same size as the source file at the position you selected. Both the symbolic link and the hard link keep the file Changing synchronously.

If you use ls to view a directory, you will find that some files are followed by a @ symbol, that is, a file generated using ln command, and you can use ls-l command to view it, the link path is displayed.

 

The difference between a hard link and a symbolic link is that the hard link has the same I-node as the original file, that is, they are the same indexes pointing to a storage space.

Files generated by hard links have the same meaning as previous file names, and because they all point to the same bucket, operations on files generated by hard links are performed, in fact, all operations are performed on that bucket.

In addition, when a bucket has several hard links, deleting one of them will not perform operations on the bucket, so other hard links will not be affected.

This method is similar to the pointer in the C language. When a bucket has several pointers pointing to it, deleting a pointer does not result in the bucket being recycled.

 

The symbolic link can be understood as the index pointing to the index of the original file. it is different from the original file. so if there are three files, a is the original file, B is the hard link of a, and c is the symbolic link of. no matter the file or directory content changes, it will change the content of other files. for the deletion of the original file, c will become unavailable, but it has no impact on B. deleting B and c will not affect any files.

Note:

 

1. The ln command creates a hard link by default.

2.-s does not mean soft, but symbolic, so it should be a symbolic link.

 

Author 21 aspnet

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.