Linux link command

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
  1. [root@localhost ~]# cd test
  2. [root@localhost test]# ls
  3. bcd
  4. [root@localhost test]# ln bcd abc.hard
  5. [root@localhost test]# ll
  6. total 0
  7. -rw-r--r--.2 root root 0Jul1219:31 abc.hard
  8. -rw-r--r--.2 root root 0Jul1219:31 bcd
  9. [root@localhost test]# vi bcd
  10. [root@localhost test]# cat abc.hard
  11. qwer
  12. [root@localhost test]# echo "dfd">> abc.hard
  13. [root@localhost test]# cat bcd
  14. qwer
  15. dfd
  16. [root@localhost test]# ls -i
  17. 67170460 abc.hard 67170460 bcd
  18. [root@localhost test]# rm bcd
  19. rm: remove regular file ?.cd?. y
  20. [root@localhost test]# cat abc.hard
  21. qwer
  22. dfd
  23. [root@localhost test]# ll -i
  24. total 4
  25. 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
  1. [root@localhost test]# ls
  2. abc
  3. [root@localhost test]# ln -s abc abc.soft
  4. [root@localhost test]# ll
  5. total 0
  6. -rw-r--r--.1 root root 0Jul1220:42 abc
  7. lrwxrwxrwx.1 root root 3Jul1220:55 abc.soft -> abc
  8. [root@localhost test]#in abc abc.hard
  9. -bash: syntax error near unexpected token `in'
  10. [root@localhost test]# ln abc abc.hard
  11. [root@localhost test]# ll
  12. total 0
  13. -rw-r--r--. 2 root root 0 Jul 12 20:42 abc
  14. -rw-r--r--. 2 root root 0 Jul 12 20:42 abc.hard
  15. lrwxrwxrwx. 1 root root 3 Jul 12 20:55 abc.soft -> abc
  16. [root@localhost test]# ls -i
  17. 67170460 abc 67170460 abc.hard 67170462 abc.soft
  18. [root@localhost test]# echo 111 >>abc
  19. [root@localhost test]# cat abc.soft
  20. 111
  21. [root@localhost test]# cat abc.hard
  22. 111
  23. [root@localhost test]# echo 222 >> abc.soft
  24. [root@localhost test]# cat abc
  25. 111
  26. 222
  27. [root@localhost test]# cat abc.soft
  28. 111
  29. 222
  30. [root@localhost test]# rm -rf abc
  31. [root@localhost test]# ll
  32. total 4
  33. -rw-r--r--. 1 root root 8 Jul 12 20:59 abc.hard
  34. lrwxrwxrwx. 1 root root 3 Jul 12 20:55 abc.soft -> abc
  35. [root@localhost test]# cat abc.hard
  36. 111
  37. 222
  38. [root@localhost test]# rm -rf abc.soft
  39. [root@localhost test]# ll
  40. total 4
  41. -rw-r--r--. 1 root root 8 Jul 12 20:59 abc.hard
  42. [root@localhost test]# touch abc
  43. [root@localhost test]# ln -s abc.soft
  44. [root@localhost test]# ls
  45. abc abc.hard abc.soft
  46. [root@localhost test]# ll -i
  47. total 4
  48. 67170462 -rw-r--r--. 1 root root 0 Jul 12 21:01 abc
  49. 67170460 -rw-r--r--. 1 root root 8 Jul 12 20:59 abc.hard
  50. 67170463 lrwxrwxrwx. 1 root root 8 Jul 12 21:01 abc.soft -> abc.soft
  51. [root@localhost test]# rm -rf *
  52. [root@localhost test]# ll
  53. total 0
  54. [root@localhost test]# touch abc
  55. [root@localhost test]# ln -s abc abc.soft
  56. [root@localhost test]# ll
  57. total 0
  58. -rw-r--r--. 1 root root 0 Jul 12 21:05 abc
  59. lrwxrwxrwx. 1 root root 3 Jul 12 21:05 abc.soft -> abc
  60. [root@localhost test]# ln -s abc /tmp/ab.soft
  61. [root@localhost test]# ll /tmp
  62. total 0
  63. lrwxrwxrwx. 1 root root 3 Jul 12 21:06 ab.soft -> abc
  64. drwxr-xr-x. 3 root root 16 Jul 12 19:33 japan
  65. [root@localhost test]# ll /tmp
  66. total 0
  67. lrwxrwxrwx. 1 root root 3 Jul 12 21:06 ab.soft -> abc
  68. drwxr-xr-x. 3 root root 16 Jul 12 19:33 japan
  69. [root@localhost test]# rm -rf /tmp/ab.soft
  70. [root@localhost test]# ln -s /root/test/abc /tmp/ab.soft
  71. [root@localhost test]# ll /tmp
  72. total 0
  73. lrwxrwxrwx. 1 root root 14 Jul 12 21:08 ab.soft -> /root/test/abc
  74. drwxr-xr-x. 3 root root 16 Jul 12 19:33 japan
Six hard link and soft link file access diagram


 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326145862&siteId=291194637