English willing link
Format: ln –s [ source file ] [ target file ]
-s create soft link
Create a soft link
[root@localhost tmp]# ln -s yum.log yum.soft
[root@localhost tmp]# ll
total 8
drwxr-xr-x. 2 root root 45 Apr 23 21:42 cn
-rwx------. 1 root root 836 Apr 22 16:09 ks-script-f3PaWI
-rw-------. 1 root root 9 Apr 23 22:27 yum.log
lrwxrwxrwx. 1 root root 7 Apr 23 22:27 yum.soft -> yum.log
Windows - like shortcuts
Soft link permissions are relatively large, and any user has read, write and execute permissions
Create a hard link
[root@localhost tmp]# ln yum.log yum.hard
[root@localhost tmp]# ll
total 12
drwxr-xr-x. 2 root root 45 Apr 23 21:42 cn
-rwx------. 1 root root 836 Apr 22 16:09 ks-script-f3PaWI
-rw-------. 2 root root 9 Apr 23 22:27 yum.hard
-rw-------. 2 root root 9 Apr 23 22:27 yum.log
lrwxrwxrwx. 1 root root 7 Apr 23 22:27 yum.soft -> yum.log
difference between the two
1. Hard links will be updated synchronously
The same as the original file, the content and attributes of the file are similar to the file copied by the command cp -p
But there is one feature: the content will be updated synchronously
No matter which file is updated, the other file will be updated synchronously
When the original file is deleted, the soft link cannot be accessed, the hard link can still be accessed, and the content remains unchanged.
2. Hard links cannot span partitions
Hard links cannot cross partitions, soft links can cross partitions
[root@localhost tmp]# ln yum.log /boot/yum.hard
ln: failed to create hard link ‘/boot/yum.hard’ => ‘yum.log’: Invalid cross-device link
3. Hard links cannot be directories
Hard links cannot be directories, soft links can be directories
[root@localhost tmp]# ln cn cn2
ln: ‘cn’: hard link not allowed for directory
4. The maximum permission of soft links is lrwxrwxrwx
The permission of the soft link file is 3 rwx , all soft links have this permission
lrwxrwxrwx
How to distinguish original file from hard link? Use the ls -i command to see if the IDs are the same
[root@localhost tmp]# ll -i
total 12
5596 drwxr-xr-x. 2 root root 45 Apr 23 21:42 cn
16777327 -rwx------. 1 root root 836 Apr 22 16:09 ks-script-f3PaWI
16777321 -rw-------. 2 root root 9 Apr 23 22:27 yum.hard
16777321 -rw-------. 2 root root 9 Apr 23 22:27 yum.log
16777679 lrwxrwxrwx. 1 root root 7 Apr 23 22:27 yum.soft -> yum.log