a grammar
ln -s [source file] [destination file]
Command English meaning: link
Function description: Generate link file
Options: -s create soft link
Two hard link features
It is fine to delete either the original file or the hard link file.
Three hard links in practice
[root@localhost ~]# cd test
[root@localhost test]# ls
bcd
[root@localhost test]# ln bcd abc.hard
[root@localhost test]# ll
total 0
-rw-r--r--.2 root root 0Jul1219:31 abc.hard
-rw-r--r--.2 root root 0Jul1219:31 bcd
[root@localhost test]# vi bcd
[root@localhost test]# cat abc.hard
qwer
[root@localhost test]# echo "dfd">> abc.hard
[root@localhost test]# cat bcd
qwer
dfd
[root@localhost test]# ls -i
67170460 abc.hard 67170460 bcd
[root@localhost test]# rm bcd
rm: remove regular file ?.cd?. y
[root@localhost test]# cat abc.hard
qwer
dfd
[root@localhost test]# ll -i
total 4
67170460-rw-r--r--.1 root root 10Jul1220:39 abc.hard
Four soft link features
1. Delete the original file, the soft link file cannot be used.
2. Although the permission of the soft link file is 777, the real permission is still determined by the original file.
3. When creating a soft link, if the original file and the target file are in the same directory, there is no need to write the absolute path, otherwise the original file and the target file must write the absolute path. So the original file must write the absolute path.
Five actual combat
[root@localhost test]# ls
abc
[root@localhost test]# ln -s abc abc.soft
[root@localhost test]# ll
total 0
-rw-r--r--.1 root root 0Jul1220:42 abc
lrwxrwxrwx.1 root root 3Jul1220:55 abc.soft -> abc
[root@localhost test]#in abc abc.hard
-bash: syntax error near unexpected token `in'
[root@localhost test]# ln abc abc.hard
[root@localhost test]# ll
total 0
-rw-r--r--. 2 root root 0 Jul 12 20:42 abc
-rw-r--r--. 2 root root 0 Jul 12 20:42 abc.hard
lrwxrwxrwx. 1 root root 3 Jul 12 20:55 abc.soft -> abc
[root@localhost test]# ls -i
67170460 abc 67170460 abc.hard 67170462 abc.soft
[root@localhost test]# echo 111 >>abc
[root@localhost test]# cat abc.soft
111
[root@localhost test]# cat abc.hard
111
[root@localhost test]# echo 222 >> abc.soft
[root@localhost test]# cat abc
111
222
[root@localhost test]# cat abc.soft
111
222
[root@localhost test]# rm -rf abc
[root@localhost test]# ll
total 4
-rw-r--r--. 1 root root 8 Jul 12 20:59 abc.hard
lrwxrwxrwx. 1 root root 3 Jul 12 20:55 abc.soft -> abc
[root@localhost test]# cat abc.hard
111
222
[root@localhost test]# rm -rf abc.soft
[root@localhost test]# ll
total 4
-rw-r--r--. 1 root root 8 Jul 12 20:59 abc.hard
[root@localhost test]# touch abc
[root@localhost test]# ln -s abc.soft
[root@localhost test]# ls
abc abc.hard abc.soft
[root@localhost test]# ll -i
total 4
67170462 -rw-r--r--. 1 root root 0 Jul 12 21:01 abc
67170460 -rw-r--r--. 1 root root 8 Jul 12 20:59 abc.hard
67170463 lrwxrwxrwx. 1 root root 8 Jul 12 21:01 abc.soft -> abc.soft
[root@localhost test]# rm -rf *
[root@localhost test]# ll
total 0
[root@localhost test]# touch abc
[root@localhost test]# ln -s abc abc.soft
[root@localhost test]# ll
total 0
-rw-r--r--. 1 root root 0 Jul 12 21:05 abc
lrwxrwxrwx. 1 root root 3 Jul 12 21:05 abc.soft -> abc
[root@localhost test]# ln -s abc /tmp/ab.soft
[root@localhost test]# ll /tmp
total 0
lrwxrwxrwx. 1 root root 3 Jul 12 21:06 ab.soft -> abc
drwxr-xr-x. 3 root root 16 Jul 12 19:33 japan
[root@localhost test]# ll /tmp
total 0
lrwxrwxrwx. 1 root root 3 Jul 12 21:06 ab.soft -> abc
drwxr-xr-x. 3 root root 16 Jul 12 19:33 japan
[root@localhost test]# rm -rf /tmp/ab.soft
[root@localhost test]# ln -s /root/test/abc /tmp/ab.soft
[root@localhost test]# ll /tmp
total 0
lrwxrwxrwx. 1 root root 14 Jul 12 21:08 ab.soft -> /root/test/abc
drwxr-xr-x. 3 root root 16 Jul 12 19:33 japan
Six hard link and soft link file access diagram