Linux Comm Ln
# Linux ln Command
[ Linux Command Manual](#)
The Linux ln (full English name: link files) command is a very important command. Its function is to create a synchronous link for a file at another location.
When we need to use the same file in different directories, we don't need to place an identical copy of the file in every required directory. We only need to place the file in one fixed directory and then use the ln command to link (link) it in other directories, avoiding redundant disk space usage.
### Syntax
ln where the options format is [-V {numbered,existing,simple}]
**Command Function**:
In the Linux file system, there are so-called links (link), which we can think of as aliases for files. Links can be divided into two types: hard links (hard link) and symbolic links (symbolic link). 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 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 occupy a very small amount of disk space.
**Symbolic Link**:
* 1. A symbolic link exists in the form of a path. It is similar to a shortcut in the Windows operating system.
* 2. Symbolic links can span file systems, while hard links cannot.
* 3. Symbolic links can link to a non-existent file name.
* 4. Symbolic links can link to directories.
**Hard Link**:
* 1. A hard link exists in the form of a file copy. However, it does not occupy actual space.
* 2. Creating hard links for directories is not allowed.
* 3. Hard links can only be created within the same file system.
#### Command Options
**Required Options**:
* --backup Back up existing target files
* -b Similar to **--backup**, but does not accept arguments
* -d Allow superusers to create hard links for directories
* -f Force execution
* -i Interactive mode, prompts the user whether to overwrite if the file exists
* -n Treat symbolic links as normal directories
* -s Symbolic link (soft link)
* -v Display detailed processing information
**Optional Options**:
* -S "-S" or "--suffix="
* -V "-V" or "--version-control="
* --help Display help information
* --version Display version information
### Examples
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 Manual](#)
YouTip