ArticleDirectory
- Option
- Note:
- Example
- Tips
Create a link for a file
Ln [Options]Existing-File[New-Link]
Ln [Options]Existing-file-List Directory
Ln can create hard links or symbolic (soft) links for one or more files. For directories, you can only create symbolic links, but not hard links.
Parameters
The first format:Existing-FileIs the path name of the file to create a link,New-LinkIs the path name of the new link. When creating a symbolic link,Existing-FileIt can be a directory.
If omittedNew-Link, Ln is in the working directoryExisting-FileCreate a link.Existing-FileSame file name
Second format:Existing-file-listIs the list of path names of common files to create links,LnIn the DirectoryDirectoryCreates a new link with the same name as the original file.
Option
-B. If the target link to be created already has the same file name, back up
-F force create target Link
-I prompt when overwriting the same file name
-S: Create a symbolic link
Note:
Hard link:By default, ln is used to create hard links. Hard links cannot be distinguished from the original files and cannot point to directories. All hard links to the same file must be in the same file system,
Symbolic Link:Symbolic Links can point to directories and can be located in different file systems.
Example Ln create hard link
$Ln/Home/Siu/Backupname. SQL. $Ls-L total usage0-RW-r --2Siu0January7 13:01Backupname. SQL
A file hard link is created in the current directory.
Ln-s create a symbolic link
$Ln-S/tmp /./ABC $Ls-L total usage0Lrwxrwxrwx1Siu5January8 20:07ABC->/tmp/
Here, a symbolic link/ABC is created for/tmp.
Ln-sb
$ ln - Sb aa bb $ ls - L total usage 0 -RW-r -- 1 Siu 0 August 1, January 8 20 : 11 aalrwxrwxrwx 1 Siu 2 August 1, January 8 20 : 11 BB-> AA -RW-r -- 1 Siu 0 August 1, January 8 20 : 11 BB ~
Create a symbolic link and back up existing files
Ln-SF
$ Ln -S Aa CC Ln : Unable to Create Symbolic Link " CC " : The file already exists $ Ln -SF AA CC $ Ls - L total usage 0 -RW-r -- 1 Siu 0 January 8 20 : 11 Aalrwxrwxrwx 1 Siu 2 January 8 20 : 11 Bb-> AA -RW-r -- 1 Siu 0 January 8 20 : 11 Bb ~ Lrwxrwxrwx 1 Siu 2 January 8 20 : 13 CC -> AA
Force Create Symbolic Link
Ln-Si
$Ln-Si AA bbLn: Whether to replace"Bb"? Y $Ls-L total usage0-RW-r --1Siu0January8 20:14Aalrwxrwxrwx1Siu2January8 20:14Bb-> AA
Prompt when creating a symbolic link
Tips
1. Hard links are usually the same as common files and cannot tell whether they are links.
2. The hard link size attribute is the same as that of the original file. If you delete the original file, the hard link can also be used.
3. Hard links have certain limitations. Therefore, symbolic links are widely used.