Liunx软链接和硬链接
Liunx软链接(又称符号链接,即 soft link 或 symbolic link)与硬链接 (hard link)
硬链接(基于索引节点的共享方式)
如果A文件和B文件的关系是硬连接的关系。当用户修改了A文件的内容,那么B文件的内容也会发生更改。如果修改的B文件,那么A文件的内容也会发生更改。
特点:
1、硬连接不限于两个文件之间,可以在多个文件之间进行。
ls -l命令中显示了文件的硬连接数(显示的是索引节点上count的值,用来表示链接到本索引节点上的用户目录项的数目)
2、不能对目录做硬件连接
3、不能在不同的文件系统之间做硬链接(Linux的文件系统:ext4,xfs等等) df -T查看文件系统
4、所有的硬连接,具备相同的iNode节点号。
[root@liucentos:/root]# touch file1
[root@liucentos:/root]# ln file1 file2
[root@liucentos:/root]# ls
1.txt anaconda-ks.cfg file1 file2 install_panel.sh sqlite.db
[root@liucentos:/root]# ll -l
总用量 72
-rw-r--r-- 1 root root 0 3月 24 10:24 1.txt
-rw-------. 1 root root 1651 3月 19 19:27 anaconda-ks.cfg
-rw-r--r-- 2 root root 0 4月 7 09:41 file1
-rw-r--r-- 2 root root 0 4月 7 09:41 file2
-rw-r--r--. 1 root root 58075 3月 19 19:49 install_panel.sh
-rw-r--r-- 1 root root 8192 3月 28 21:58 sqlite.db
[root@liucentos:/root]# echo 'aaa' > file1
[root@liucentos:/root]# cat file1
aaa
[root@liucentos:/root]# cat file2
aaa
软连接(基于符号链实现的文件共享)
类似Windows中的快捷方式,为一个源文件创建一个快捷方式。
1、如果源文件被删除了,也没有办法使用该快捷方式。一旦以同样文件名创建了源文件,链接将继续指向该文件的新数据
2、在ls -l中,软链接作为一种特殊的文件类型显示出来,其第一个字母是1。
3、软链接的大小是其链接文件的路径名中的字符数。
rm 软连接 删除该符号链接
rm -rf 使用该命令删除软连接的目录 目录最后加/ 会删除文件,而不是这个软连接的符号链接
相关命令
ln命令
用来创建硬链接和软连接
ln file1 file2 #给file1创建硬连接,注意,跨不了文件系统
ln -s 源文件或目录 软链接的文件或目录 #使用绝对路径,不要使用相对路径
ln -s file1 file3 #给file1创建软连接,使用绝对路径,不要使用相对路径
pwd -P 显示文件的实际路径,而不是软连接接的路径
[root@liucentos:/root]# cd /bin/
[root@liucentos:/bin]# pwd
/bin
[root@liucentos:/bin]# pwd -P
/usr/bin
df -T 查看文件系统的类型
总结
软链接通过指向源文件的路径建立链接,硬链接通过索引节点建立链接。
软链接可以跨文件系统,硬链接不能。软链接可以对目录创建链接,硬链接不可以。
删除软链接和硬链接都不影响源文件。
解除软链接和硬链接,直接删除链接文件即可。
参考链接:
https://blog.csdn.net/weixin_42301220/article/details/134520854

浙公网安备 33010602011771号