[Shell] 纯文本查看 复制代码
[iyunv@localhost ln]# pwd
/usr/ln
[iyunv@localhost ln]# ll
总计 0
# 测试1:
# 分别建立源文件(skyex)、硬链接(sHLink)、软链接(sSLink)
[iyunv@localhost ln]# touch skyex
[iyunv@localhost ln]# ln skyex sHLink
[iyunv@localhost ln]# ln -s skyex sSLink
[iyunv@localhost ln]# ll
总计 0
-rw-r--r-- 2 root root 0 03-31 16:56 sHLink
-rw-r--r-- 2 root root 0 03-31 16:56 skyex
lrwxrwxrwx 1 root root 5 03-31 16:56 sSLink -> skyex
# 测试2:
# 硬链接不允许链接目录和文件系统
# 软链接可以链接目录和文件系统
[iyunv@localhost ln]# ln /usr/ln /tmp
ln: "/usr/ln" : 不允许将硬链接指向目录
[iyunv@localhost ln]# ln -s /usr/ln /tmp
[iyunv@localhost ln]# ll /tmp |grep ln
lrwxrwxrwx 1 root root 7 03-31 16:58 ln -> /usr/ln
# 测试3:
# 源文件、软链接、硬链接更改任意一个文件的内容,其他的文件内容同时改变
# ①更改源文件的内容
[iyunv@localhost ln]# cat>skyex<<eof
> this is main
> eof
[iyunv@localhost ln]# cat sHLink sSLink
this is main
this is main
# ②更改硬链接的内容
[iyunv@localhost ln]# cat>sHLink<<eof
> this is sHLink
> eof
[iyunv@localhost ln]# cat skyex sSLink
this is sHLink
this is sHLink
# ③更改软链接的内容
[iyunv@localhost ln]# cat>sSLink<<eof
> this is sSLink
> eof
[iyunv@localhost ln]# cat skyex sSLink
this is sSLink
this is sSLink
# 测试4:
# 删除软硬链接,对源文件没有影响
[iyunv@localhost ln]# rm -rf sHLink sSLink
[iyunv@localhost ln]# cat skyex
this is sSLink
# --->重建
[iyunv@localhost ln]# ln skyex sHLink
[iyunv@localhost ln]# ln -s skyex sSLink
[iyunv@localhost ln]# ll
总计 8
-rw-r--r-- 2 root root 15 03-31 17:01 sHLink
-rw-r--r-- 2 root root 15 03-31 17:01 skyex
lrwxrwxrwx 1 root root 5 03-31 17:03 sSLink -> skyex
# 测试5:
# 删除源文件,硬链接可以正常读取数据;软链接无法正常读取数据
[iyunv@localhost ln]# rm -f skyex
[iyunv@localhost ln]# ll
总计 4
-rw-r--r-- 1 root root 15 03-31 17:01 sHLink
lrwxrwxrwx 1 root root 5 03-31 17:03 sSLink -> skyex
[iyunv@localhost ln]# cat sHLink
this is sSLink
[iyunv@localhost ln]# cat sSLink
cat: sSLink: 没有那个文件或目录
[iyunv@localhost ln]# ll
总计 4
-rw-r--r-- 1 root root 15 03-31 17:01 sHLink
lrwxrwxrwx 1 root root 5 03-31 17:03 sSLink -> skyex