Linux中硬链接和软链接的使用和区别

硬链接和软链接的区别:

1、硬链接不能跨分区进行链接

2、硬链接不能对目录进行链接,软链接可以

3、iNode硬链接和源文件相同,软链接和源文件不相同

实例:

ln -s [源文件] [目标文件]
   -s 创建软链接
    
# 例子
[root@localhost ~]# cat /etc/issue
\S
Kernel \r on an \m

[root@localhost ~]# ln -s /etc/issue /tmp/issue.conf   # 创建软链接
[root@localhost ~]# ll /etc/issue
-rw-r--r--. 1 root root 23 Apr  7  2020 /etc/issue
[root@localhost ~]# cat /tmp/issue.conf
\S
Kernel \r on an \m

[root@localhost ~]# ln /etc/issue /tmp/issue2.conf   # 创建硬链接
[root@localhost ~]# ll /etc/issue   # 硬链接引用计数+1,变成2
-rw-r--r--. 2 root root 23 Apr  7  2020 /etc/issu

# 查看软硬链接文件类型
[root@localhost ~]# ll /tmp/
-rw-r--r--. 2 root root 23 Apr  7  2020 issue2.conf  # 硬链接,相当于cp -p 拷贝文件+共同更新
lrwxrwxrwx. 1 root root 10 Nov  2 21:53 issue.conf -> /etc/issue   # 软链接都是l类型,满权限

# 查看软硬链接文件的i索引
[root@localhost ~]# ls -i /etc/issue /tmp/issue.conf /tmp/issue2.conf 
16778316 /etc/issue  16778316 /tmp/issue2.conf  19061552 /tmp/issue.conf  # 硬链接索引号和源文件一样,软链接不一样
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值