Linux command: ln Use method

  

Command: ln Usage method

Instruction name: ln

Usage rights: All users

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

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

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

Description: There is a so-called link in the Linux/Unix file system. We can treat it as an alias for the file, and the link can be divided into two types: A hard link and a symbolic link (symbolic link). A hard link means that a file can have multiple names, and a soft link creates a special file. The content of the file points to another The location of a file. Hard links exist in the same file system, while soft links can span different file systems.

ln source dist is to generate a dist to source, as far as using hard links or soft links is determined by parameters.

No hard link or soft link will copy the original file, it will take up a very small amount of disk space.

Parameter format:

-f : Delete the file with the same name as dist first.

-d : Allow system administrator to hard link their own directory

-i : Ask when you delete a file with the same name as dist

-n : When making a soft link, treat dist as a normal file

-s : Perform a symbolic link

-v : Display the file name before the link

-b : Back up the file that will be overwritten or deleted at the time of the link

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

-V METHOD : Specify the backup method

--help : Display auxiliary instructions

--version : Display version

Example:

Generate a symbolic link to the file yy: zz

ln -s yy zz

Generate a hard link to the file yy: zz

ln yy xx

Use of the ln command (F)

ln This is a very important command in linux. Its function is to create a link to a file in another location. The most common parameter of this command is -s. The specific usage is: ln -s source file object file. When we need to use the same file in different directories, we don't need to put a file that must be the same in every required directory. We just put it in a fixed directory, put it in the other, then in the other In the directory, you can use the ln command link (link), you do not have to use disk space repeatedly. For example: ln -s /bin/less /usr/local/bin/less -s is the meaning of the symbolic (symbolic). There are two points to note here: First, the ln command will keep the synchronization of each linked file, that is, no matter which part you change, the other files will change the same; Second, the link of ln Also divided into symbolic links and hard links, the symbolic link is ln -s ** **, it will only generate a mirror image of the file at the location you choose, does not take up disk space, hard link ln ** * *, without the parameter -s, it will generate a file of the same size as the source file at the location you selected, whether it is a symbolic link or a hard link, the file will keep changing. If you use ls to view a directory, you will find a file with a @ symbol, which is a file generated with the ln command. Use the ls -l command to view it and you can see the path of the displayed link. 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 indiscriminately pointing to an index of the space in which the data is stored. The file generated by the hard link has the same meaning as the previous file name. Moreover, since all of them are indistinguishable to point to the same storage space, the operations performed on the files generated by the hard links are actually operations on that storage space. Moreover, when a storage space has several hard links, one of them is deleted, and the storage space is not operated, so other hard links are not affected. This way, similar to the pointer in the C language, when there are several pointers to a storage space pointing to it, deleting one of the pointers does not bring the storage space to be recycled. A symbolic link can be understood as an index pointing 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, and b is the hard link of a, and c is the symbolic link of a. Just the content change of that file or directory will change the content of other files. For the deletion of the original file, c will become unavailable, but has no effect on b.b , the deletion of c will not affect any file. Note: 1. For the ln command, the default is to establish a hard link. 2.. -s is not soft (soft) meaning, but the meaning of symbolic (symbol), so it should be Symbolic link.

Copyright © Windows knowledge All Rights Reserved