硬连接与软连接

原文参考: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)删除软连接并不影响原文件,但删除原文件,软连接则成了死连接。但是当你重新创建源文件,该软连接又恢复正常
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值