使用cp创建硬链接和软连接
扫码查看 原文链接 : https://blog.lmlphp.com/tutorial/1/SHELL/item/2/Use_cp_to_create_hard_links_and_soft_links 来自 : LMLPHP后院
使用 cp -l 创建硬链接:
$ ls -il total 0 1049097 -rw-r--r-- 1 may may 0 Dec 15 15:46 a.txt $ test cp -l a.txt b.txt $ test ls -il total 0 1049097 -rw-r--r-- 2 may may 0 Dec 15 15:46 a.txt 1049097 -rw-r--r-- 2 may may 0 Dec 15 15:46 b.txt
使用 cp -s 创建软链接:
$ cp -s a.txt c.txt $ test l -il total 8.0K 1052326 drwxr-xr-x 2 may may 4.0K Dec 15 15:48 . 1049106 drwxr-xr-x 6 may may 4.0K Dec 15 15:46 .. 1049097 -rw-r--r-- 2 may may 0 Dec 15 15:46 a.txt 1049097 -rw-r--r-- 2 may may 0 Dec 15 15:46 b.txt 1053673 lrwxrwxrwx 1 may may 5 Dec 15 15:48 c.txt -> a.txt
另外使用 ln 也可以创建硬链接,创建软链接同样需要加上参数 -s 。
注意,硬链接只能在相同挂载点的文件系统上创建。