Establish a link to a file
ln [options] existing-file [new-link]
ln [options] existing-file-list directory
LN can create a hard-link or symbolic (soft) link for one or more files. For a table of contents, you can create only symbolic links, not hard links
Parameters
First format:existing-file is the pathname of the file to create the link to, andNew-link is the path name of the new link. When you create a symbolic link,existing-file can be a directory.
If new-linkis omitted, LN creates a link in the working directory for Existing-file , using the same file name as existing-file
Second format:existing-file-list is the list of path names for the normal file to create the link,ln creates a new link in directory directory with the same link name as the original file name
Options
-B If you need to create a target link that already has the same file name, the backup
-F Force Create a target link
-I prompt when overwriting the same file name
-S creating Symbolic links
Attention
Hard Links: By default, LN creates hard links that are indistinguishable from the original file and cannot point to the directory. All hard links to the same file must be in the same file system,
Symbolic Links: Symbolic Links can point to directories and can reside in different file systems
ExampleLN Creates a hard link
$ ln/home/siu/backupname.sql. $ ls-l Total Usage 0-rw-r--r--2 siu siu 0 January 7 13:01 backupname.sql
This creates a hard link to a file in the current directory, followed by a. can also omit
Ln-s Creating Symbolic Links
$ ln-s/tmp/./abc$ ls-l Total dosage 0lrwxrwxrwx 1 siu siu 5 January 8 20:07 ABC-/tmp/
A symbolic link has been created for/tmp here/ABC
LN-SB
$ LN-SB AA bb$ ls-l total dosage 0-rw-r--r--1 siu siu 0 January 8 20:11 aalrwxrwxrwx 1 siu Siu 2 January 8 20:11 BB-A a-rw-r--r--1 siu Siu 0 January 8 20:11 bb~
Create symbolic links and back up existing files
LN-SF
$ ln-s AA CCLN: Unable to create symbolic link "cc": File already exists $ LN-SF AA cc$ ls-l Total usage 0-rw-r--r--1 siu siu 0 January 8 20:11 aalrwxrwxrwx 1 si U Siu 2 January 8 20:11 bb, aa-rw-r--r--1 siu siu 0 January 8 20:11 bb~lrwxrwxrwx 1 siu Siu 2 January
8 20:13 cc-A AA
Force creation of Symbolic links
Ln-si
$ ln-si AA bbln: Do you want to replace "BB"? y$ ls-l Total dosage 0-rw-r--r--1 siu siu 0 January 8 20:14 aalrwxrwxrwx 1 siu Siu 2 January 8 20:14 BB-AA
Prompt when creating a symbolic link
Tips
1. Hard links are usually the same as normal files, and cannot distinguish between their links
2. Hard link Size property as with the original file, if you delete the original file, hard links can also be used
3. Hard links have some limitations, so the scope of the symbolic link is more widely used
50-LN Concise Notes