zoukankan      html  css  js  c++  java
  • 硬连接和软连接

    硬连接(hard link)

    创建:

    ln source target.hlink

    | filename | inode # |
    +--------------------+
                    \
                     >-------> | permbits, etc | addresses |
                    /          +---------inode-------------+
    | othername | inode # |                         \
    +---------------------+                          `--------> | data | | data | etc
                                                                +------+ +------+

    多个硬连接指向同一个inode。引用计数为0且无进程打开时可以删除文件内容。

    缺陷:

    不能为目录创建(hard link not allowed for directory);不能用在不同的文件系统。

    Tips:

    1. 目录是一种特殊的文件,在构建的过程中产生两个特殊的文件: ...

    . 是指向当前目录文件的硬连接, .. 是指向当前目录父目录的硬连接。/ 是个例外,.. 也指向/ 。

    2. 创建隐藏的临时文件

    #include <stdio.h>
    #include <unistd.h>
    
    int main() {
      FILE *fp = fopen("some.hidden.file","w+");
      sleep(5); // ls to find the file
      unlink("some.hidden.file"); // deletes the filename part
      // some.hidden.file no longer has a filename and is truely hidden
    
      // can still access the data part
      {
        fprintf(fp,"This data won't be found any more\n");
        rewind(fp);
        char str[80];
        fgets(str, 80, fp);
        printf("%s", str);
      }
      sleep(5);
      fclose(fp); // finally release the data part
    }

    软连接(soft link / symbolic link)

    创建:

    ln -s source target.slink

          | filename | inode # |
          +--------------------+
                          \
                           `-------> | permbits, etc | addresses |
                                     +---------inode-------------+
                                                        /
                                                       /
                                                      /
      ,----------------------------------------------'
     (
      `-->  |"/path/to/some/other/file"|
            +---------data-------------+
                    /                      }
      ,~ ~ ~ ~ ~ ~ ~                       }-- (redirected at open() time)
     (                                     }
      `~~> | filename | inode # |
           +--------------------+
                           \
                            `------------> | permbits, etc | addresses |
                                           +---------inode-------------+

    软连接也是一种特殊的文件,存储了其指向文件的路径。

    缺陷:

    额外的io操作;占用更多硬盘空间;source移动后不能访问。

  • 相关阅读:
    Chapter 2: 随机变量
    数据集
    Chapter 1: 随机事件及其概率
    概率论与数理统计每周教学内容及作业
    概率论与数理统计教学内容
    Entity Framework search sequnce
    Runtime Complexity of .NET Generic Collection
    update the UI property cross thread
    打通技术的任督二脉
    windbg symbol path
  • 原文地址:https://www.cnblogs.com/chenkkkabc/p/2968577.html
Copyright © 2011-2022 走看看