Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Linux ln command

Linux ln command

Linux Command Reference Linux Command Reference

The Linux ln command (short for "link files") is a very important command; its function is to create a synchronized link to a file at another location.

When we need to use the same file in different directories, we do not need to place an identical copy in every directory. We only need to put the file in one fixed directory and then use the ln command to link it in the other directories, without repeatedly taking up disk space.

Syntax

 ln [参数][源文件或目录][目标文件或目录]

The format of the parameter is

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

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

Command function :
In the Linux file system, there are so-called links, which we can regard as aliases for a file. Links can be divided into two types: hard links and symbolic links. A hard link means a file can have multiple names, while a symbolic link creates a special file whose content points to the location of another file. Hard links must exist within the same file system, while symbolic links can span different file systems.

Neither hard links nor symbolic links copy the original file; they only take up a very small amount of disk space.

Symbolic link:

Hard link:

Command Parameters

Required Parameters:

Select parameters:

Example

Create a symbolic link for a file: create a symbolic link link2013 for the file log2013.log. If log2013.log is lost, link2013 will become invalid:

ln -s log2013.log link2013

Output:



[root@localhost test]# ll

-rw-r--r-- 1 root bin      61 11-13 06:03 log2013.log

[root@localhost test]# ln -s log2013.log link2013

[root@localhost test]# ll

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

-rw-r--r-- 1 root bin      61 11-13 06:03 log2013.log

Create a hard link for a file: create a hard link ln2013 for log2013.log; log2013.log and ln2013 have identical attributes

ln log2013.log ln2013

Output:



[root@localhost test]# ll

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

-rw-r--r-- 1 root bin      61 11-13 06:03 log2013.log

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

[root@localhost test]# ll

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

-rw-r--r-- 2 root bin      61 11-13 06:03 ln2013

-rw-r--r-- 2 root bin      61 11-13 06:03 log2013.log

Linux Command Reference Linux Command Reference