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节点,所以在内核中这两个是一个文件,会被同时修改。
    • 软连接是一个链接,是一个单独的文件

    删除源文件后:

    • 软连接失效
    • 硬链接仍然生效
  • 相关阅读:
    VB.NET中lambda的写法
    C#中DllImport用法和路径问题
    SQL*Loader 和 Data Pump
    批处理-函数定义及应用01
    Office 2010 KMS激活原理和案例分享
    Hyper-V架构与VMware ESXi的差异
    Tomcat免安装配置2
    Tomcat免安装配置
    域名解析过程
    内部类访问的局部变量必须加final
  • 原文地址:https://www.cnblogs.com/zhangnianlei/p/12242341.html
Copyright © 2011-2022 走看看