原文参考:https://www.ibm.com/developerworks/cn/linux/l-cn-hardandsymb-links/index.html#fig2
使用stat 命令查看iNode号
[root@localhost ~]# stat install.log
File: `install.log'
Size: 41364 Blocks: 96 IO Block: 4096 regular file
Device: 802h/2050d Inode: 130308 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2018-11-26 19:07:30.019512710 -0800
Modify: 2018-11-20 09:27:19.610999900 -0800
Change: 2018-11-20 09:27:29.484999899 -0800
将文件移动位置后,再次查看inde号,可以看到inode以及用户的一些数据信息是没有变的
[root@localhost ~]# mv install.log /mnt/
[root@localhost ~]# stat /mnt/install.log
File: `/mnt/install.log'
Size: 41364 Blocks: 96 IO Block: 4096 regular file
Device: 802h/2050d Inode: 130308 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2018-11-26 19:07:30.019512710 -0800
Modify: 2018-11-20 09:27:19.610999900 -0800
Change: 2018-11-26 19:19:05.230511969 -0800
硬连接:一个inode有多个文件名
创建方法 ln oldfile newfile
特性:
(1)文件有相同的 inode 及 data block
(2)不能对目录进行创建、仅能对已存在的文件进行创建
(3)不能跨文件系统创建
(4)创建后用stat查看时可以看到Links数会增加
(5)删除硬链接不会影响原文件
软连接:符号连接,soft link ,symbolic link
[root@localhost ~]# ln -s /root/install.log /mnt/soft_install
[root@localhost ~]# ll /mnt/soft_install
lrwxrwxrwx 1 root root 17 Nov 26 23:52 /mnt/soft_install -> /root/install.log
[root@localhost ~]# stat /mnt/soft_install
File: `/mnt/soft_install' -> `/root/install.log'
Size: 17 Blocks: 0 IO Block: 4096 symbolic link
Device: 802h/2050d Inode: 397350 Links: 1
Access: (0777/lrwxrwxrwx) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2018-11-26 23:52:30.942007051 -0800
Modify: 2018-11-26 23:52:29.226010249 -0800
Change: 2018-11-26 23:52:29.226010249 -0800
[root@localhost ~]# stat /root/install.log
File: `/root/install.log'
Size: 41364 Blocks: 96 IO Block: 4096 regular file
Device: 802h/2050d Inode: 130308 Links: 2
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2018-11-26 22:51:16.932011470 -0800
Modify: 2018-11-20 09:27:19.610999900 -0800
Change: 2018-11-26 22:51:06.994010990 -0800
创建方法:
ln -s oldfile newfile
特性:
(1)软连接有自己的inode以及数据特性
(2)可对不存在的文件或目录创建
(3)可交叉文件系统,可对目录创建
(4)用stat查看时Links数量不会增加
(5)删除软连接并不影响原文件,但删除原文件,软连接则成了死连接。但是当你重新创建源文件,该软连接又恢复正常