重学Linux - 链接文件

重学Linux - 链接文件


@auther 张念磊
@date 2020/1/30

ln命令

命令英文:link

功能:创建一个链接

语法:ln [源文件] [生产的链接文件]

参数:

​ -s 生成软连接

示例:

ln -s /etc/issue /tmp/issue.soft
ln /etc/issur /tmp/issue.hard 
软连接文件的特点
  • 权限

  • 文件大小

  • 箭头

硬链接特征
  • 拷贝 cp -p + 实时同步
  • 不能跨分区
  • 使用i节点
  • 不能针对目录使用
额外
echo 'zhangnlei.cn' >> /etc/issue

往文件底部附加一行数据

演示
添加链接文件
[root@VM_81_142_centos ~]# # 查看源文件
[root@VM_81_142_centos ~]# cat /etc/issue
Centos 7
Kernel \r on an \m
zhangnlei.cn
[root@VM_81_142_centos ~]# 
[root@VM_81_142_centos ~]# # 添加软连接
[root@VM_81_142_centos ~]# ln -s /etc/issue /tmp/issue.soft
[root@VM_81_142_centos ~]# cat /tmp/issue.soft
Centos 7
Kernel \r on an \m 
zhangnlei.cn
[root@VM_81_142_centos ~]#
[root@VM_81_142_centos ~]# # 添加硬链接
[root@VM_81_142_centos ~]# ln /etc/issue /tmp/issue.hard
[root@VM_81_142_centos ~]# cat /tmp/issue.hard
Centos 7
Kernel \r on an \m
zhangnlei.cn
[root@VM_81_142_centos ~]#
[root@VM_81_142_centos ~]# # 修改源文件
[root@VM_81_142_centos ~]# echo "zhangnianlei's blog" >> /etc/issue
[root@VM_81_142_centos ~]# cat /etc/issue
Centos 7
Kernel \r on an \m
zhangnlei.cn
zhangnianlei's blog
[root@VM_81_142_centos ~]# cat /tmp/issue.soft
Centos 7
Kernel \r on an \m
zhangnlei.cn
zhangnianlei's blog
[root@VM_81_142_centos ~]# cat /tmp/issue.hard
Centos 7
Kernel \r on an \m
zhangnlei.cn
zhangnianlei's blog
[root@VM_81_142_centos ~]#
[root@VM_81_142_centos ~]#
文件比较
[root@VM_81_142_centos ~]# ll /etc/issue
-rw-r--r-- 2 root root 63 1月  30 10:28 /etc/issue
[root@VM_81_142_centos ~]# ll /tmp
总用量 16
-rw-r--r-- 2 root root   63 1月  30 10:28 issue.hard
lrwxrwxrwx 1 root root   10 1月  30 10:23 issue.soft -> /etc/issue
  • 文件权限:软连接的权限是全部允许,硬链接的权限和源文件相同

  • 文件类型:软连接的文件类型是:l(软连接),硬链接的文件类型同源文件一致:-(文件)

  • 文件大小:硬链接与源文件一致,软连接较小。

查看i节点
[root@VM_81_142_centos ~]# # 查看i节点
[root@VM_81_142_centos ~]# ls -i /etc/issue /tmp/issue.soft /tmp/issue.hard
278955 /etc/issue  278955 /tmp/issue.hard     952 /tmp/issue.soft
[root@VM_81_142_centos ~]# 
  • 源文件与硬链接使用同一个i节点,所以在内核中这两个是一个文件,会被同时修改。
  • 软连接是一个链接,是一个单独的文件

删除源文件后:

  • 软连接失效
  • 硬链接仍然生效
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值