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

二 硬链接特征
原文件和硬链接文件删除其中任何一个都没问题。
三 硬链接实战
[[email protected] ~]# cd test[[email protected] test]# lsbcd[[email protected] test]# ln bcd abc.hard[[email protected] test]# lltotal 0-rw-r--r--.2 root root 0Jul1219:31 abc.hard-rw-r--r--.2 root root 0Jul1219:31 bcd[[email protected] test]# vi bcd[[email protected] test]# cat abc.hardqwer[[email protected] test]# echo "dfd">> abc.hard[[email protected] test]# cat bcdqwerdfd[[email protected] test]# ls -i67170460 abc.hard 67170460 bcd[[email protected] test]# rm bcdrm: remove regular file ?.cd?. y[[email protected] test]# cat abc.hardqwerdfd[[email protected] test]# ll -itotal 467170460-rw-r--r--.1 root root 10Jul1220:39 abc.hard
四 软链接特征
1、把原文件删除,软链接文件无法使用。
2、虽然软链接文件的权限是777,但真正的权限还是由原文件决定。
3、创建软链接时,如果原文件和目标文件在一个目录下,不用写绝对路径,否则原文件和目标文件必须写绝对路径。所以原文件一定要写绝对路径。
五 实战
[[email protected] test]# lsabc[[email protected] test]# ln -s abc abc.soft[[email protected] test]# lltotal 0-rw-r--r--.1 root root 0Jul1220:42 abclrwxrwxrwx.1 root root 3Jul1220:55 abc.soft -> abc[[email protected] test]#in abc abc.hard-bash: syntax error near unexpected token `in'[[email protected] test]# ln abc abc.hard[[email protected] test]# lltotal 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.hardlrwxrwxrwx. 1 root root 3 Jul 12 20:55 abc.soft -> abc[[email protected] test]# ls -i67170460 abc 67170460 abc.hard 67170462 abc.soft[[email protected] test]# echo 111 >>abc[root[email protected] test]# cat abc.soft111[[email protected] test]# cat abc.hard111[[email protected] test]# echo 222 >> abc.soft[[email protected] test]# cat abc111222[[email protected] test]# cat abc.soft111222[[email protected] test]# rm -rf abc[[email protected] test]# lltotal 4-rw-r--r--. 1 root root 8 Jul 12 20:59 abc.hardlrwxrwxrwx. 1 root root 3 Jul 12 20:55 abc.soft -> abc[[email protected] test]# cat abc.hard111222[[email protected] test]# rm -rf abc.soft[[email protected] test]# lltotal 4-rw-r--r--. 1 root root 8 Jul 12 20:59 abc.hard[[email protected] test]# touch abc[[email protected] test]# ln -s abc.soft[[email protected] test]# lsabc abc.hard abc.soft[[email protected] test]# ll -itotal 467170462 -rw-r--r--. 1 root root 0 Jul 12 21:01 abc67170460 -rw-r--r--. 1 root root 8 Jul 12 20:59 abc.hard67170463 lrwxrwxrwx. 1 root root 8 Jul 12 21:01 abc.soft -> abc.soft[[email protected] test]# rm -rf *[[email protected] test]# lltotal 0[[email protected] test]# touch abc[[email protected] test]# ln -s abc abc.soft[[email protected] test]# lltotal 0-rw-r--r--. 1 root root 0 Jul 12 21:05 abclrwxrwxrwx. 1 root root 3 Jul 12 21:05 abc.soft -> abc[[email protected] test]# ln -s abc /tmp/ab.soft[[email protected] test]# ll /tmptotal 0lrwxrwxrwx. 1 root root 3 Jul 12 21:06 ab.soft -> abcdrwxr-xr-x. 3 root root 16 Jul 12 19:33 japan[[email protected] test]# ll /tmptotal 0lrwxrwxrwx. 1 root root 3 Jul 12 21:06 ab.soft -> abcdrwxr-xr-x. 3 root root 16 Jul 12 19:33 japan[[email protected] test]# rm -rf /tmp/ab.soft[[email protected] test]# ln -s /root/test/abc /tmp/ab.soft[[email protected] test]# ll /tmptotal 0lrwxrwxrwx. 1 root root 14 Jul 12 21:08 ab.soft -> /root/test/abcdrwxr-xr-x. 3 root root 16 Jul 12 19:33 japan
六 硬链接和软链接文件访问示意图