English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The Linux ln (full English name: link files) command is a very important command, its function is to create a synchronized link at another location for a certain file
When we need to use the same file in different directories, we do not need to place a file that must be the same in each directory where it is needed. We just need to place the file in a fixed directory, and then use the ln command to link (link) it in other directories, without duplicating disk space
ln [parameters][source file or directory][target file or directory]The format of the parameters is
[-bdfinsvF] [-S backup-suffix] [-V {numbered,existing,simple}]
[--help] [--version] [--]
Command function :
In the Linux file system, there is a concept of links (link), which we can consider as aliases for files, and links can be divided into two types: hard links (hard link) and soft links (symbolic link). The meaning of hard links is that a file can have multiple names, while the method of soft links is to create a special file whose content points to the location of another file. Hard links exist within the same file system, while soft links can cross different file systems
Neither hard links nor soft links will copy the original file; they will only occupy a very small amount of disk space
Soft link:
Hard link:
Required Parameters:
Select Parameters:
Create a symbolic link for the file, for log2013.log file creates a symbolic link link2013, if log2013.log lost, link2013Will 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 the file, for log2013.log creates a hard link ln2013, log2013.log and ln2013have the same 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