Linux common Commands (28)-Ln

Source: Internet
Author: User

LN is another very important command in Linux, and its function is to create a synchronized link for a file in another location. 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.

1. command format:

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


2. command function:

Linuxfilesystem, there are so-calledlinks(link), which we can treat as an alias to the file, andlinkscan also be divided into two types: hardlinks(hard link) and softlinks(symbolic Link), HardlinksIt means that a file can have multiple names, while the softlinksthe way is to produce a special file, the content of the file is pointing to another file location. Hardlinksthere is the samefilesystem, while the softlinksbut you can cross a differentfileSystem.


Soft Links:

1. Soft links , which exists in the form of a path. Similar to shortcuts in the Windows operating system

2. Soft links can cross file system, hard links not to

3. Soft links a file name that does not exist can be links

4. Soft links the directory can be links


Hard Links:

1. Hard link, in the form of a copy of the file. But does not occupy the actual space.

2. Do not allow the creation of hard links 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 maintains the synchronization of each linked file, meaning that no matter where you change it, the other files will change the same.

Second, Ln's links are soft links and hard links two, soft link is the ln–s source file destination file, it will only generate a file in your selected location image, will not occupy disk space, hard link ln source file destination file, no parameter-s, It will generate a file of the same size as the source file in the location you selected, whether it is a soft link or a hard link, and the file keeps changing synchronously.

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


3. Command parameters:

Necessary parameters:

-B Delete, overwrite previously established link

-D allows super users to make hard links to directories

-F Force Execution

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

-N treats symbolic links as generic directories

-S soft link (symbolic link)

-V displays detailed processing procedures


Select parameters:

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

-V "-v< backup method >" or "--version-control=< backup method >"

--HELP Display Help information

--version displaying version information


4. usage Examples:

Example one: Creating a soft link to a file

command: ln-s log2013.log link2013

Description: Create soft link link2013 for Log2013.log file, link2013 will expire if Log2013.log is lost

[[email protected] test]# ll-rw-r--r--1 root bin      11-13 06:03 log2013.log[[email protected] test]# ln-s Log2013.lo G Link2013[[email protected] test]# lllrwxrwxrwx 1 root root one 12-07 16:01 link2013-log2013.log-rw-r--r--     1 roo T bin      11-13 06:03 log2013.log

Example two:Create a hard link to a file

Command:ln log2013.log ln2013

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

[[email protected] test]# lllrwxrwxrwx 1 root root one     12-07 16:01 link2013-log2013.log-rw-r--r--1 root bin      11-13 06:03 log2013.log[[email protected] test]# ln log2013.log ln2013[[email protected] test]# lllrwxrwxrwx 1 root Roo T     12-07 16:01 link2013, log2013.log-rw-r--r--2 root bin-      11-13 06:03 Log2013.log


Example three: Creating a soft link to a directory
Command: LN-SV/OPT/SOFT/TEST/TEST3/OPT/SOFT/TEST/TEST5

[[email protected] test]# lldrwxr-xr-x 2 root root 4096 12-07 16:36 test3drwxr-xr-x 2 root root 4096 12-07 16:57 Test5[[email protected] test]# CD test5[[email protected] test5]# lllrwxrwxrwx 1 root root 5 12-07 16:57 test3- > test3[[email protected] test5]# CD TEST3-BASH:CD:TEST3: Excessive number of layers of symbolic connections [[email protected] test5]# [[email& Nbsp;protected] test5]# [[email protected] test5]# lllrwxrwxrwx 1 root root 5 12-07 16:57 test3-TEST3[[EMAIL&NB Sp;protected] test5]# rm-rf test3[[email protected] test5]# ll[[email protected] test5]# ln-sv/opt/soft/ TEST/TEST3/OPT/SOFT/TEST/TEST5 Create a symbolic link "/opt/soft/test/test5/test3" to "/opt/soft/test/test3" [[email   Protected] test5]# lllrwxrwxrwx 1 root root 12-07 16:59 test3-/opt/soft/test/test3[[email protected] test5]# [[email protected] test5]# CD test3[[email protected] test3]# ll-rw-r--r--2 root root 12-07 16:36 log2013.l Og[[email protected] test3]# Touch log2014.log[[Email protected] test3]# ll-rw-r--r--2 root root 12-07 16:36 log2013.log-rw-r--r--1 root root 0 12-07 17:05 log 2014.log[[email protected] test3]# CD. [[email protected] test5]# CD.
Description

1. directories can only create soft links

2. Directory Creation link must use absolute path, relative path creation will not be successful, will prompt: the number of layers of the symbolic connection too many such errors

3. modifying files in the target directory of the link changes synchronously in the source file directory

Original address: http://www.cnblogs.com/peida/archive/2012/12/11/2812294.html



Linux common Commands (28)-Ln

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.