Linux command: ln use method

Source: Internet
Author: User

Directive Name: LN

Use Rights: All users

How to use: ln [options] Source dist, where option is in the form of:

[-BDFINSVF] [-S Backup-suffix] [-v {numbered, existing, simple}]

[--help] [--version] [--]

Note: Linux/unix file system, there are so-called links (link), we can treat it as a file alias, and the link can be divided into two kinds: hard link (hard link) and soft link (symbolic Link) (Symbolic connection), A hard link means that a file can have multiple names, and the soft link is to create a special file that points to the location of another file. Hard links exist in the same file system, while soft links can span different file systems.

The LN source Dist produces a link (dist) to source, as with a hard link or a soft link is determined by the parameter.

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

Parameter format:

-F: First delete files with dist file name when linking

-D: Allows system managers to hard link their own directories

-I: Ask before deleting files with the same file name as Dist

-N: Dist is considered a general file when soft links are made

-S: Soft link (symbolic link)

-V: Displays the file name before the link

-B: Backup files that will be overwritten or deleted when the link is made

-S SUFFIX: Add the backup file to the end of the SUFFIX

-V Method: Specify how the backup should be

--HELP: Show Auxiliary Instructions

--version: Display version

Example:

The file yy generates a symbolic link:zz

Ln-s yy ZZ

The file yy generates a hard link:zz

ln yy XX

Use of ln command (F)

ln This is a very important command in Linux. Its function is for a file in another location to establish a link, the most common parameter is-s, the specific use is: Ln-s source file Destination file.

When we need to use the same file in a different directory, we don't need to put a file that must be the same in every directory we need, we just put the file in a certain directory, and then use the LN command link in the other directory to make it available, without duplicating the disk space. For example: Ln-s/bin/less/usr/local/bin/less

-S is the meaning of the Code name (symbolic).

Here are two points to note:

First, the LN command keeps the synchronization of each linked file, which means that no matter which one you change, the other files will change the same.

Second, the links in Ln are divided into symbolic links and hard links, symbolic link is ln-s * * * *, it will only in the location you selected to generate a file image, does not occupy disk space, hard link LN * * * *, no parameter-s, it will be in the location you selected to generate a file and the same size as the source file, The files remain synchronized, whether they are symbolic links or hard links.

If you use LS to look at a directory, found that there is a file behind a @ symbol, that is a file in the ln command generated, with the ls-l command to view, you can see the path of link displayed.

A hard link differs from a symbolic link in that a hard link has the same i-node as the original file, which is an undifferentiated index to the space where the data is stored.

Hard links produce files that have the same meaning as previous filenames, and because they point to the same storage space with no difference, the operation of the files generated by the hard link is actually the operation of that storage space.

Also, when a storage space has several hard links, deleting one of them does not operate on the storage space, so other hard links are not affected.

This way, like a pointer in C, when a few pointers in a storage space point to it, deleting one of the pointers does not result in the operation of the storage space being reclaimed.

Symbolic links can be interpreted as indexes that point to the index of the original file. It is two different files from the original file. So if there are three files, a is the original file, B is a hard link, and C is a The symbolic link. The contents of the file or directory change will make the contents of other files change. For the deletion of the original file, C will become unavailable, and B has no effect. The deletion of b,c does not affect any files.

Note:

1. For the ln command, the default is to establish a hard link.

2.-S is not soft (soft) meaning, but symbolic (symbol) meaning, so should be symbolic link.

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.