Linux Base command (%) ln command

Source: Internet
Author: User

LN is another very important command in Linux, and its function is to create an identical link for a file in another location. When we need to use the same file in a different directory, we don't need to put a file in every directory that needs to be the same, we just have to be in a certain directory, Put the file on it, and then use the LN command link in the other directory to make it available without duplicating disk space.

1. Command format:

ln [parameter] [source file or directory] [destination file or directory]

2. Command function:

Linux file system, there is a so-called 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), hard link means that a file can have more than one name, The soft link is generated by a special file that points to the location of another file. Hard links exist in the same file system, but soft links can span different file systems.

Soft Link:

1. Soft links, in the form of paths exist. Similar to shortcuts in Windows operating systems

2. Soft link can cross file system, hard link 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 document. But does not occupy the actual space.

2. Do not allow the creation of a hard link 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 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 soft links and hard links, soft link is the ln–s source file, it will only be in your chosen location to generate a file image, will not occupy disk space, hard link in the source file target file, no parameter-s, it will be in your selected bit To generate a file with the same size as the source file, whether it is a soft link or a hard link, the files remain synchronized.

The ln instruction is used in a linked file or directory, such as specifying more than two files or directories, and the last destination is an existing directory, and all files or directories previously specified are copied to that directory. If you specify multiple files or directories at the same time, and the last destination is not an existing directory, an error message appears.

3. Command parameters:

Necessary parameters:

-B Delete, overwrite previously established links

-D allows super users to make hard links to directories

-F Enforcement

-I interactive mode, file presence prompts the user whether to overwrite

-N treats symbolic links as generic directories

-S soft link (symbolic link)

-V Display detailed process

Select parameters:

-S "-s< tail backup string >" or "--suffix=< tail backup string >"

-V "-v< backup mode >" or "--version-control=< Backup mode >"

--HELP Display Help information

--Version Display release information

4. Use instance:

Example 1: Create a soft link to a file

Command:

Ln-s Log2013.log link2013

Output:

[Root@localhost test]# LL

-rw-r--r--1 Root bin 11-13 06:03 Log2013.log

[Root@localhost test]# ln-s Log2013.log link2013

[Root@localhost test]# LL

lrwxrwxrwx 1 root 12-07 16:01 link2013-> log2013.log

-rw-r--r--1 Root bin 11-13 06:03 Log2013.log

Description

Create a soft link for the Log2013.log file link2013, link2013 will fail if Log2013.log is lost

Example 2: Create a hard link to a file

Command:

ln Log2013.log ln2013

Output

[Root@localhost test]# LL

lrwxrwxrwx 1 root 12-07 16:01 link2013-> log2013.log

-rw-r--r--1 Root bin 11-13 06:03 Log2013.log

[root@localhost test]# Ln log2013.log ln2013

[Root@localhost test]# LL

lrwxrwxrwx 1 root 12-07 16:01 link2013-> log2013.log

-rw-r--r--2 Root bin 11-13 06:03 ln2013

-rw-r--r--2 Root bin 11-13 06:03 Log2013.log

Description

Create a hard link for log2013.log ln2013,log2013.log the same properties as ln2013

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.