Linux ln command
Linux ln command
Linux ln command is a very important command, its function is to establish a certain file synchronization link in another location.
When we need in a different directory, use the same file, we do not need in the directory of every need to put a file must be the same, as long as we are in a fixed catalog, put the file, and then in the other under a directory with the ln command links (link) it can, without having to repeat the disk space.
grammar
ln [参数][源文件或目录][目标文件或目录]Wherein the format parameter is
[-bdfinsvF] [-S Backup-suffix] [-V {numbered, existing, simple}]
[--help] [--version] [-]
Use this command:
Linux file system, so-called link (link), we can consider it an alias file, and the link can be divided into two types: hard link (hard link) and soft link (symbolic link), the meaning of hard links a file can have multiple names, and the soft link is a way to generate a special file, the contents of the file are pointing to another file location. A hard link is the presence of the same file system, but it can be a soft link across different file systems.
Whether soft or hard links will not link a copy of the original file, only occupy a very small amount of disk space.
Soft links:
- 1. soft links, in the form of a path exists. Similar to the Windows operating system shortcuts
- 2. Soft links across file systems, hard links can not be
- 3. The soft link to a file name that does not exist link
- 4. soft link to the directory link
Hard Links:
- 1. hard link, in the form of a copy of the file exists. But do not take the actual space.
- 2. The directory is not allowed to create hard links
- 3. The only hard links in the same file system can be created
Command Parameters
Necessary parameters:
- -b delete, overwrite previously established links
- -d allows the superuser to make hard links to directories
- -f enforcement
- -i interactive mode, the user is prompted if the file exists overwrite
- -n generally regarded as the symbolic link directory
- -s soft links (symbolic links)
- -v Displays detailed process
Selection parameters:
- -S "-S <Backup suffix string>" or "--suffix = <backup suffix string>"
- -V "-V <Backup>" or "--version-control = <backup>"
- --help display help information
- --version display version information
Examples
Create a soft link to the file, create a soft link link2013 as log2013.log file, if log2013.log lost, link2013 will fail:
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 to the file, create a hard link to log2013.log ln2013, the same attributes and ln2013 of log2013.log
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