最後更新: 2021-02-19
目錄
readlink
Print resolved symbolic links(找出指向的 file) or canonical file names
i.e.
ln -s test.txt link.txt
readlink link.txt
test.txt
Hard Link
Work with hardlink
mkdir tmp; cd tmp
echo test > a.txt
ln a.txt b.txt # b.txt --hard link--> a.txt
ls -i1 # -i --inode, hard link file 係有相同 inode
712963 a.txt 712963 b.txt
亦可以用 stat
stat a.txt
File: a.txt
Size: 5 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 712963 Links: 2
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2022-01-03 13:20:38.053478553 +0800
Modify: 2022-01-03 13:20:38.053478553 +0800
Change: 2022-01-03 13:20:41.541419430 +0800
Birth: -
find . -inum # 找出 hardlink 出什麼 file
./a.txt ./b.txt
# -xdev # limit to one filesystem
# ! -type d reject directories. the . and .. entries mean they're always linked.
find tmp/ -xdev \! -type d -links +1 # 找出有 hardlink 的 file
Hard link with rsync
# 沒有 Hard Link 時
rsync -a tmp 192.168.88.31:/root
# On Host 192.168.88.31
ls -i1 tmp/
17537802 a.txt 17537805 b.txt
# Hard Link 時
rsync -aH tmp 192.168.88.31:/root
ls -i1 tmp/
17537802 a.txt 17537802 b.txt
no-dereference
# treat LINK_NAME as a normal file if it is a symbolic link to a directory
-n, --no-dereference
應用
ln -sfn /usr/local/bin/python3.7 /usr/bin/python3.7