ln

最後更新: 2021-02-19

 


readlink

 

Print resolved symbolic links or canonical file names

i.e.

ln -s test.txt link.txt

readlink link.txt

test.txt

 


Hard Link

 

Work with hardlink

mkdir tmp

echo test > tmp/a.txt

ln tmp/a.txt tmp/b.txt           # hard link, 亦可以用 stat

ls -i1 tmp/                      # --inode

33640805 -rw-r--r-- 2 root root 5 Feb 18 22:47 a.txt
33640805 -rw-r--r-- 2 root root 5 Feb 18 22:47 b.txt

find tmp/ -inum 33640805             # 找出 hardlink 出什麼 file

tmp/a.txt
tmp/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

rsync -a tmp 192.168.88.31:/root

# On Host 192.168.88.31

ls -i1 tmp/

17537802 a.txt
17537805 b.txt

rsync -aH tmp 192.168.88.31:/root

ls -i1 tmp/

17537802 a.txt
17537802 b.txt