zoukankan      html  css  js  c++  java
  • 重学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 
     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 
     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 
     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 
     on an m
    zhangnlei.cn
    zhangnianlei's blog
    [root@VM_81_142_centos ~]# cat /tmp/issue.soft
    Centos 7
    Kernel 
     on an m
    zhangnlei.cn
    zhangnianlei's blog
    [root@VM_81_142_centos ~]# cat /tmp/issue.hard
    Centos 7
    Kernel 
     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节点,所以在内核中这两个是一个文件,会被同时修改。
    • 软连接是一个链接,是一个单独的文件

    删除源文件后:

    • 软连接失效
    • 硬链接仍然生效
  • 相关阅读:
    [Evolution in aciton] C#1.1=>2.0=>3.0 [Querying Collections]
    动态操作.Config文件
    设计模式代理模式(Proxy Model)
    Linq Coding Part Five (Join之内部联接查询)
    Linq Coding Part Four[Concat应用]
    [转]领域模型管理与AOP
    08端午节,休闲一下吧,来上游戏
    有关于ViewState的二种压缩方式
    AddOutParameter引发类型问题
    Linq Coding Part Two[标准查询运算符]
  • 原文地址:https://www.cnblogs.com/zhangnianlei/p/12242341.html
Copyright © 2011-2022 走看看