junxnone / linux

Linux wiki
https://junxnone.github.io/linux/
0 stars 0 forks source link

Tools File ln #33

Open junxnone opened 4 years ago

junxnone commented 4 years ago

ln 文件链接工具

软链接 - 符号链接 - symbolic link

ln -s src_dir your_dir
$ ln -s test test_1
$ ln -s test test_2
$ ll
-rw-r--r--  1 xxx xx 29 Mar  8 15:33 test
lrwxrwxrwx  1 xxx xx  4 Mar  8 15:34 test_1 -> test
lrwxrwxrwx  1 xxx xx  4 Mar  8 15:34 test_2 -> test

硬链接 - hard link

$ ln  test test_3
$ ln  test test_4
$ ll
-rw-r--r--  3 xxx xx  29 Mar  8 15:33 test
lrwxrwxrwx  1 xxx xx  4 Mar  8 15:34 test_1 -> test
lrwxrwxrwx  1 xxx xx  4 Mar  8 15:34 test_2 -> test
-rw-r--r--  3 xxx xx  29 Mar  8 15:33 test_3
-rw-r--r--  3 xxx xx  29 Mar  8 15:33 test_4

test3 test4 为硬链接, 所以引用数变为 3


$ rm test
$ ll
lrwxrwxrwx  1 xxx xx      4 Mar  8 15:34 test_1 -> test
lrwxrwxrwx  1 xxx xx      4 Mar  8 15:34 test_2 -> test
-rw-r--r--  2 xxx xx     29 Mar  8 15:33 test_3
-rw-r--r--  2 xxx xx     29 Mar  8 15:33 test_4

Reference