[[email protected] home]# mkdir testln    创建一个用于测试的文件夹
[[email protected] home]# cd testln/      进入该文件夹
[[email protected] testln]# vim test.txt  创建测试的txt文件,并写入内容
[[email protected] testln]# cat test.txt  查看写入的内容
hello world
[[email protected] testln]# ln test.txt test.ln 创建硬链接的链接文件
[[email protected] testln]# ll
总用量 8
-rw-r--r-- 2 root root 12 9月  11 15:24 test.ln    会发现硬链接的链接文件也是普通文件类型
-rw-r--r-- 2 root root 12 9月  11 15:24 test.txt
[[email protected] testln]# cat test.ln   查看硬链接的文件内容与原文件内容一致
hello world
[[email protected] testln]# vim test.ln   更改硬链接文件的内容
[[email protected] testln]# cat test.ln   查看更改后硬链接文件的内容
hello world
hello linux
[[email protected] testln]# cat test.txt  查看原文件内容,发现与链接文件内容一致更改
hello world
hello linux
[[email protected] testln]# ln -s test.txt  在已创建硬链接的文件创建软连接文件,发现无法创建
ln: 创建符号链接 "./test.txt": 文件已存在
[[email protected] testln]# vim test2.txt   创建第二个测试文件并编写内容
[[email protected] testln]# cat test2.txt   查看文件内容
hello test2.txt
[[email protected] testln]# ln -s test2.txt test2.ln  创建软链接文件
[[email protected] testln]# ll  
总用量 12
lrwxrwxrwx 1 root root  9 9月  11 15:26 test2.ln -> test2.txt 此处显示软链接文件是l连接文件
-rw-r--r-- 1 root root 16 9月  11 15:26 test2.txt
-rw-r--r-- 2 root root 24 9月  11 15:24 test.ln
-rw-r--r-- 2 root root 24 9月  11 15:24 test.txt
[[email protected] testln]# cat test2.ln  查看软链接文件内容与原文件一致
hello test2.txt
[[email protected] testln]# vim test2.ln  更该软链接的文件内容
[[email protected] testln]# cat test2.txt 查看原文件内容,发现一并更改
hello test2.txt
hello linux

linux的连接文件简单介绍

创建硬链接文件后,原文件和硬链接文件都指向文件的内容,而且两个文件都是文本文件,当删除原文件时,只是删除了源文件的名字,不会删除文件内容,所以,硬链接文件仍然可以查看修改文件内容

创建软链接的文件则是指向了原文件的名称,并不是指向文件的内容,所以当删除原文件时,软链接文件会频闪提示,而删除硬链接文件就不会

linux的连接文件简单介绍

相关文章: