Linux链接命令

一 语法

ln -s [源文件] [目标文件]
命令英文含义:link
功能描述:生成链接文件
选项:-s 创建软链接
 
二 硬链接特征


 
原文件和硬链接文件删除其中任何一个都没问题。
 
三 硬链接实战
  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
 四 软链接特征


 
1、把原文件删除,软链接文件无法使用。
2、虽然软链接文件的权限是777,但真正的权限还是由原文件决定。
3、创建软链接时,如果原文件和目标文件在一个目录下,不用写绝对路径,否则原文件和目标文件必须写绝对路径。所以原文件一定要写绝对路径。
五 实战
  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
六 硬链接和软链接文件访问示意图


 
  • 大小: 75.3 KB
  • 大小: 170.4 KB
  • 大小: 35.2 KB
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值