22 File Links: Hard and Symbolic

这一生的挚爱 提交于 2019-12-23 00:42:17

1 Kernel Data Structures Review

1.每个进程都有一个process table,索引是文件描述符,指向filetable
2.file table中有对文件状态的描述,比如offset
3.v-node(是虚拟文件,一切皆文件) i-node(实际的物理装置信息)

在这里插入图片描述

2 Hard Links

  1. v-nodes are the file system enteries
  2. i-nodes represent the underlying storage mechanisms for that data within that file.
  3. hard-link
    1. there are two virtual v-nodes that reference the same i-node
      在这里插入图片描述

    2. the file exists in multiple places within the file system, and can have different names. But, whenever you open that file, it is the same underlying data that is accessed.

在这里插入图片描述

2.1 Creating Links with ln

1)创建文件f,此时links是1

#> touch f
#> ls -l
-rw-r--r--  1 aviv  staff  0 Mar 23 12:51 f

# 解释
   links--.                  .--file size
           \                / 
-rw-r--r--  1 aviv  staff  0 Mar 23 12:51 f
\________/    \_________/    \__________/  \_
     |             |              |          |
permissions    user/group       mod time     file name

2)创建硬链接

#> ln f hl   #Create a hard link to f named hl
#> ls -l
total 0
-rw-r--r--  2 aviv  staff  0 Mar 23 12:51 f
-rw-r--r--  2 aviv  staff  0 Mar 23 12:51 hl

2.2 Hard Links and Directories

1..有两个连接:1).本身 2)具体的路径
2...有三个连接:两个来自于.,还有一个来自..本身

#> ls -lia
34996362 drwxr-x--- 2 aviv scs 4096 Mar 23 18:14 .
34996236 drwxr-x--- 3 aviv scs 4096 Mar 23 18:14 ..
34996364 -rw-r----- 2 aviv scs    0 Mar 23 18:14 f
34996364 -rw-r----- 2 aviv scs    0 Mar 23 18:14 hl

2.3 Un-linking is the same as removal

1.un-linked hl is that we removed it, and that is exactly what remove does
2. In other terms, the unlink command removes an entry from the file system by removing a link.

#> ls -li
total 0
34996364 -rw-r----- 2 aviv scs 0 Mar 23 18:14 f
34996364 -rw-r----- 2 aviv scs 0 Mar 23 18:14 hl
#> unlink hl
#>ls -l
total 0
-rw-r----- 1 aviv scs 0 Mar 23 18:14 f

2.4 Hard-linking across file systems

3 Symbolic Links

  1. Symbolic Links
    1. Symbolic Linking is when one file links to another file, which refernces the underlying file block.
      在这里插入图片描述

    2. 类似于win的shortcut

在这里插入图片描述

3.1 Creating Symbolic Links

#> ln -s f sl
#> ls -l
-rw-r----- 1 aviv scs 0 Mar 23 18:14 f
lrwxrwxrwx 1 aviv scs 1 Mar 23 18:44 sl -> f

3.2 Dangling Links

#> rm f
rm: remove regular empty file `f'? y
#> ls -l
lrwxrwxrwx 1 aviv scs 1 Mar 23 18:44 sl -> f
#> cat sl
cat: sl: No such file or directory

3.3 Symbolic Links across Files Systems

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!