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

    删除源文件后:

    • 软连接失效
    • 硬链接仍然生效
  • 相关阅读:
    加州大学Santa Barbara量化课程
    专利分析与申请(2):SILK 专利的特点
    两种可分级语音编码器的量化器
    芬兰赫尔辛基工业大学DirAC工程:Directional audio coding
    SILK 的 Delay Decision 和 Dither
    Fraunhofer 研究院
    ICASSP 论文发表相关问题
    SILK 学习总结之位分配与低码率编码
    今天测试VOIP软件结果
    国内部分音频语音相关研究企业(实时更新)
  • 原文地址:https://www.cnblogs.com/zhangnianlei/p/12242341.html
Copyright © 2011-2022 走看看