---
# System prepended metadata

title: 作業一參考詳解

---

# 作業一參考詳解

## 目標

建立如下的目錄結構，並透過 **符號連結 (symbolic link)** 與 **硬連結 (hard link)** 完成連結

```
~/LSA/
├── MOLi/
│   ├── Kaiwha/
│   └── Leafish/   ←→ (hard link with ARG/Archigo)
├── ARG/
│   ├── Archigo/   ←→ (hard link with MOLi/Leafish)
│   └── Hanwei/
└── Reg -> MOLi/Kaiwha   (symbolic link)
```

## 參考解法

```bash
mkdir -p ~/LSA/{MOLi/,ARG/} \
&& touch ~/LSA/{MOLi/{Kaiwha,Leafish},ARG/Hanwei} \
&& ln -s ~/LSA/MOLi/Kaiwha ~/LSA/Reg \
&& ln ~/LSA/MOLi/Leafish ~/LSA/ARG/Archigo
```

## 驗證結果

### 確認目錄結構

```bash
tree -L 2 -F ~/LSA
```

輸出:

```
/root/LSA/
|-- ARG/
|   |-- Archigo
|   `-- Hanwei
|-- MOLi/
|   |-- Kaiwha
|   `-- Leafish
`-- Reg -> /root/LSA/MOLi/Kaiwha
```

### 確認 Leafish 及 Archigo 為 hard link

1. 用編輯器 (vim, nano, etc.) 建立 `ckhdlink.sh` 檔案，並填入以下內容後儲存

```bash!
#!/usr/bin/env bash
# 用法: ./ckhdlink.sh path1 path2

if [ $# -ne 2 ]; then
    echo "用法: $0 <path1> <path2>"
    exit 1
fi

inode1=$(stat -c %i "$1")
inode2=$(stat -c %i "$2")

if [ "$inode1" -eq "$inode2" ]; then
    echo "$1 和 $2 是硬連結 (inode=$inode1)"
else
    echo "$1 和 $2 不是硬連結"
    echo "$1 inode=$inode1"
    echo "$2 inode=$inode2"
fi
```

2. 給腳本執行權限

```bash!
chmod +x ckhdlink.sh
```

3. 執行腳本

```bash!
./ckhdlink.sh ~/LSA/ARG/Archigo ~/LSA/MOLi/Leafish
```

輸出:

```
/root/LSA/ARG/Archigo 和 /root/LSA/MOLi/Leafish 是硬連結 (inode=...)
```