1、在test底下创建a、a的硬链接、a的软链接
[root@localhost test]# touch a
[root@localhost test]# ls
a
[root@localhost test]# ln /test/a a.hard
[root@localhost test]# ls
a a.hard
[root@localhost test]# ln -s /test/a a.soft
[root@localhost test]# ls
a a.hard a.soft
2、在a文件添加内容并查看软链接和硬链接内容
[root@localhost test]# echo 123 > a
[root@localhost test]# cat a a.hard a.soft
123
123
123
3、依次修改软硬链接内容,查看三个的内容
[root@localhost test]# echo 222 > a.hard
[root@localhost test]# cat a a.hard a.soft
222
222
222
[root@localhost test]# echo 333 > a.soft
[root@localhost test]# cat a a.hard a.soft
333
333
333
4、删除a文件,查看软链接和硬链接情况
[root@localhost test]# rm a
rm: remove regular file 'a'? y
[root@localhost test]# ls
a.hard a.soft
[root@localhost test]# cat a.hard a.soft
333
cat: a.soft: No such file or directory
硬链接正常,软链接出现报错
5、重新创建a文件并添加内容,查看a、硬链接、软连接情况
[root@localhost test]# echo 123 > a
[root@localhost test]# ls
a a.hard a.soft
[root@localhost test]# cat a a.hard a.soft
123
333
123
硬链接内容不变,软链接不再报错
该文演示了在Linux环境下创建文件a的硬链接aa.hard和软链接aa.soft的过程。内容修改时,硬链接的改动会同步到原始文件,而软链接指向的内容随源文件变化。删除原文件后,硬链接仍可访问内容,但软链接会失效。重新创建文件a并添加内容后,硬链接保持原有内容,软链接恢复功能。
104





