文件共享——软链接和硬链接对引用计数值的影响
苗锦洲
新疆
0
22
256
0
友情提示:此篇文章大约需要阅读 7分9秒
```mindmap
- 文件创建
- 直接设为1
- 创建链接
- 软链接
- 软链接的引用计数值直接设为1
- 硬链接
- 硬链接的引用计数值与原文件保持同步
- 原文件的引用计数值+1
- 删除链接
- 软链接
- 不影响
- 硬链接
- 原文件的引用计数值-1
- 删除文件
- 软链接
- 不影响,再次访问时会发现文件不存在
- 硬链接
- 原文件的引用计数值-1
```
### 实机验证
```bash
(base) ordinaryroad@OrdinaryRoad-MBP14 barrage-fly % ls -l
total 16
-rw-r--r--@ 1 ordinaryroad staff 1290 Oct 12 22:39 compose.yaml
-rw-r--r--@ 1 ordinaryroad staff 1290 Oct 22 21:45 test.yaml
(base) ordinaryroad@OrdinaryRoad-MBP14 barrage-fly % ln -s test.yaml f1
(base) ordinaryroad@OrdinaryRoad-MBP14 barrage-fly % ln -s test.yaml f2
(base) ordinaryroad@OrdinaryRoad-MBP14 barrage-fly % ln -s test.yaml f3
(base) ordinaryroad@OrdinaryRoad-MBP14 barrage-fly % ls -l
total 16
-rw-r--r--@ 1 ordinaryroad staff 1290 Oct 12 22:39 compose.yaml
lrwxr-xr-x 1 ordinaryroad staff 9 Oct 22 21:49 f1 -> test.yaml
lrwxr-xr-x 1 ordinaryroad staff 9 Oct 22 21:49 f2 -> test.yaml
lrwxr-xr-x 1 ordinaryroad staff 9 Oct 22 21:49 f3 -> test.yaml
-rw-r--r--@ 1 ordinaryroad staff 1290 Oct 22 21:45 test.yaml
(base) ordinaryroad@OrdinaryRoad-MBP14 barrage-fly % ln -s f1 f11
(base) ordinaryroad@OrdinaryRoad-MBP14 barrage-fly % ls -l
total 16
-rw-r--r--@ 1 ordinaryroad staff 1290 Oct 12 22:39 compose.yaml
lrwxr-xr-x 1 ordinaryroad staff 9 Oct 22 21:49 f1 -> test.yaml
lrwxr-xr-x 1 ordinaryroad staff 2 Oct 22 21:49 f11 -> f1
lrwxr-xr-x 1 ordinaryroad staff 9 Oct 22 21:49 f2 -> test.yaml
lrwxr-xr-x 1 ordinaryroad staff 9 Oct 22 21:49 f3 -> test.yaml
-rw-r--r--@ 1 ordinaryroad staff 1290 Oct 22 21:45 test.yaml
(base) ordinaryroad@OrdinaryRoad-MBP14 barrage-fly % ln f1 f12
(base) ordinaryroad@OrdinaryRoad-MBP14 barrage-fly % ls -l
total 24
-rw-r--r--@ 1 ordinaryroad staff 1290 Oct 12 22:39 compose.yaml
lrwxr-xr-x 1 ordinaryroad staff 9 Oct 22 21:49 f1 -> test.yaml
lrwxr-xr-x 1 ordinaryroad staff 2 Oct 22 21:49 f11 -> f1
-rw-r--r--@ 2 ordinaryroad staff 1290 Oct 22 21:45 f12
lrwxr-xr-x 1 ordinaryroad staff 9 Oct 22 21:49 f2 -> test.yaml
lrwxr-xr-x 1 ordinaryroad staff 9 Oct 22 21:49 f3 -> test.yaml
-rw-r--r--@ 2 ordinaryroad staff 1290 Oct 22 21:45 test.yaml
(base) ordinaryroad@OrdinaryRoad-MBP14 barrage-fly % ln -s f12 f122
(base) ordinaryroad@OrdinaryRoad-MBP14 barrage-fly % ls -l
total 24
-rw-r--r--@ 1 ordinaryroad staff 1290 Oct 12 22:39 compose.yaml
lrwxr-xr-x 1 ordinaryroad staff 9 Oct 22 21:49 f1 -> test.yaml
lrwxr-xr-x 1 ordinaryroad staff 2 Oct 22 21:49 f11 -> f1
-rw-r--r--@ 2 ordinaryroad staff 1290 Oct 22 21:45 f12
lrwxr-xr-x 1 ordinaryroad staff 3 Oct 22 21:52 f122 -> f12
lrwxr-xr-x 1 ordinaryroad staff 9 Oct 22 21:49 f2 -> test.yaml
lrwxr-xr-x 1 ordinaryroad staff 9 Oct 22 21:49 f3 -> test.yaml
-rw-r--r--@ 2 ordinaryroad staff 1290 Oct 22 21:45 test.yaml
(base) ordinaryroad@OrdinaryRoad-MBP14 barrage-fly % rm f122
(base) ordinaryroad@OrdinaryRoad-MBP14 barrage-fly % ls -l
total 24
-rw-r--r--@ 1 ordinaryroad staff 1290 Oct 12 22:39 compose.yaml
lrwxr-xr-x 1 ordinaryroad staff 9 Oct 22 21:49 f1 -> test.yaml
lrwxr-xr-x 1 ordinaryroad staff 2 Oct 22 21:49 f11 -> f1
-rw-r--r--@ 2 ordinaryroad staff 1290 Oct 22 21:45 f12
lrwxr-xr-x 1 ordinaryroad staff 9 Oct 22 21:49 f2 -> test.yaml
lrwxr-xr-x 1 ordinaryroad staff 9 Oct 22 21:49 f3 -> test.yaml
-rw-r--r--@ 2 ordinaryroad staff 1290 Oct 22 21:45 test.yaml
```
评论
已自动恢复阅读位置、日/夜间模式参数