English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Linux ln command

Linux Command大全

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

Syntax

 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:

  • 1.Soft links exist as paths, similar to shortcuts in the Windows operating system
  • 2.Soft links can cross file systems, whereas hard links cannot
  • 3.Soft links can link to a non-existent filename
  • 4.Soft links can link to directories

Hard link:

  • 1.Hard links exist as copies of files but do not occupy actual space
  • 2.It is not allowed to create hard links for directories
  • 3Hard links can only be created within the same file system

Command Parameters

Required Parameters:

  • -b delete, overwrite links established previously
  • -d allow superuser to create hard links to directories
  • -f force execution
  • -i interactive mode, prompt the user whether to overwrite if the file exists
  • -n treat symbolic links as general directories
  • -s symbolic link (symbolic link)
  • -v to display detailed processing process

Select Parameters:

  • -S "-S<tail backup string> "or "--suffix=<tail backup string>"
  • -V "-V<backup method>" or"--version-control=<backup method>"
  • --help to display help information
  • --version to display version information

Online Examples

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

Linux Command大全