Linux LN command details and usage

Source: Internet
Author: User

Linux LN command details and usage


LN is a very important command in Linux, and its function is to create a different link for a file in another location, the most common parameter for this command is-S, which is: ln–s source file Destination file.

1. Overview of the LN command

When we need to use the same file in different directories, we do not need to put a file in each required directory, we just put the file in a fixed directory, and then in the other directory with the ln command link it can, do not have to repeatedly occupy disk space. Example: ln–s/bin/less/usr/local/bin/less

This is similar to a shortcut under Windows, but it is different.

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

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 links between soft links and hard links two, soft link is ln–s * * *, it will only be in the location you selected to generate a file image, will not occupy disk space, hard link ln** * *, no parameter-s, it will be in the location you selected to generate a file with the same size as the source file, Files are kept in sync, whether they are soft links or hard links.

If you look at a directory with LS, and found that there is a symbol at the end of the file and the color of the file or folder is not the same, I am blue on the machine, that is a file generated with the LN command, with the ls–l command to see the link shown in the path.

You can also use the LL command directly to see the soft link and its link path.


2. Detailed instructions for the LN command

Directive Name: LN

Usage rights: All users

How to use: ln [options] Source Dist

Where option is in the format:

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

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

Note: In the Linux/unix file system, there is a so-called link, we can consider it as the alias of the file, and the link can be divided into two kinds: Hard link (hardlink) and soft link (symboliclink), hard link means that a file can have multiple names, The soft-link approach is to produce a special file with the content of the file pointing to the location of another file. Hard links exist in the same file system, while soft links can span different file systems.

LN Source Dist is the generation of a link (dist) to the source, and the use of a hard or soft link is determined by the parameter.

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

-F: the link is preceded by the Dist file deletion with the same file name

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

-I.: in the Delete with Dist A file with the same file name is asked first

-N: in the case of a soft link, the Dist as a general file

-S: to make a soft chain knot (Symboliclink)

-V: show its file name before linking

-B: files that are overwritten or deleted at the time of the link are backed up

-ssuffix: Add the backed up files SUFFIX the end of the word

-vmethod: specify how to back up

--help: Show Auxiliary Instructions

--version: Show Version

Example:

#将档案 XYY produces a symbolic link:zyyln-s xyy zyy# will file XYY produce a hard link:zyylnxyy zyy ln-s abc cde    #建立abc soft Connection Lnabc cde
    #建立abc的硬连接

PS: If you want to delete a link, just like a normal file, the RM link name is the same.

3. the difference between a soft link and a hard link

A hard link can be considered to be a file with two filenames ; The soft link is the system creates a new link file, which points to the file it refers to. In addition, soft links can be used on files and folders, while hard links are only for files.

for a file, there is a unique index point corresponding to it, and for an index contact number, you can have more than one file name corresponding to it. Therefore, the same file on the disk can access the file through a different path. Note under Linux is everything files, folders, new HDD ... can look at the file to deal with.

soft connection (symbolic link) with soft connection and hard link also called symbolic connection . Symbolic connections are equivalent to shortcuts under Windows.

It is not possible to make hard connections to folders, we usually use more soft connections.     

Example:

ln-s Source Dist # establishing a soft connection

LN Source Dist # 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 join opens a new directory entry for the file, and the hard link and the original name of the file are affirmative, in Linux they seem to be equivalent. For this reason, a hard link cannot connect files on two different file systems.

(1) Soft connections can span file systems , hard connections cannot be . The practice is to use shared files to connect aa.txt text documents under windows to Linux /root directory under bb,cc. ln-saa.txt/root/bb Connection succeeded . Ln aa.txt/root/bb failed .

(2) AboutIProblems with Nodes. Hard connections No matter how many, they point to the sameInode, theThe number of node connections increases, as long as the number of connections to the node is not0, the file persists, whether you delete the source file orConnected Files. As long as there is a presence, the file isexist(in fact, it does not divide the source file connection filebecause they point to all the sameInode). When you modify the source file or any one of the connection files, the other files will be modified synchronously. Soft links are not used directlyInode number as a file pointer,instead, use the file path masterpiece as a pointer. SoDelete a connection fileno effect on the source file, but deleting the source file, the connection file will not find the file to point to. Soft links have their ownInode,and there is a small space on the disk to store the path name.

( 3 a soft connection can connect to a nonexistent file name .

( 4 a soft connection can connect to the directory.

(5) Delete the symbolic link and delete it if it is created

RM-RF  Symbolic_name  

attention, not RM-RF symbolic_name/ .

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.