最近看軟連結跟硬連結的比較,有整理一下筆記資訊,對於硬連結的觀念是都使用同一個
inode,省硬碟空間等等,但是對於”實務”上還是不是很了解大家平常都使用在那邊?
再請大家給點指教,謝謝
[Linux筆記] 軟連結與硬連結
# /與/home位於不同的partition
[email protected]:~/workspace$ df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda1 7092728 5093676 1615720 76% /
none 4 0 4 0% /sys/fs/cgroup
udev 2013844 4 2013840 1% /dev
tmpfs 404788 1036 403752 1% /run
none 5120 0 5120 0% /run/lock
none 2023940 88 2023852 1% /run/shm
none 102400 24 102376 1% /run/user
/dev/sda3 17414428 1007348 15499356 7% /home
# 分別在/與~家目錄建立檔案與目錄
[email protected]:~/workspace$ sudo touch /file1
[email protected]:~/workspace$ touch file2
[email protected]:~/workspace$ mkdir folder1
# 硬連結不支援跨partition
[email protected]:~/workspace$ ln /file1 hardfile1
ln: failed to create hard link ‘hardfile1’ => ‘/file1’: Invalid cross-devi
ce link
[email protected]:~/workspace$ ln -s /file1 softfile1
[email protected]:~/workspace$ ln file2 hardfile2
# 硬連結不支援目錄
[email protected]:~/workspace$ ln folder1 hardfolder1
ln: ‘folder1’: hard link not allowed for directory
[email protected]:~/workspace$ ln -s folder1 softfolder1
# 軟連結的檔案inode不同(965, 667577),硬連結的檔案inode相同(667572)
# 軟連結的屬性不同為變777(rwx),硬連結的屬性相同(-rw-rw-r