拓展:Linux 链接的概念(了解即可!)
拓展:Linux 链接的概念(了解即可!)
Linux的链接分为两种:硬链接、软链接!
硬链接:A—-B,假设B是A的硬链接,那么他们两个指向了同一个文件!允许一个文件拥有多个路径,用户可以通过这种机制建立硬链接到一些重要文件上,防止误删!
软链接: 类似Window下的快捷方式,删除的源文件,快捷方式也访问不了!
- 创建连接 ln 命令!
touch命令创建文件!echo输入字符串,也可以输入到文件中!


[root@kuangshen home]# touch f1 # 创建一个f1文件
[root@kuangshen home]# ls
f1 install.sh kuangshen www
[root@kuangshen home]# ln f1 f2 # 创建一个硬链接 f2
[root@kuangshen home]# ls
f1 f2 install.sh kuangshen www
[root@kuangshen home]# ln -s f1 f3 # 创建一个软链接(符号连接) f3
[root@kuangshen home]# ls
f1 f2 f3 install.sh kuangshen www
[root@kuangshen home]# ll
total 28
-rw-r--r-- 2 root root 0 Mar 24 20:17 f1
-rw-r--r-- 2 root root 0 Mar 24 20:17 f2
lrwxrwxrwx 1 root root 2 Mar 24 20:18 f3 -> f1
-rw-r--r-- 1 root root 20078 Mar 4 16:48 install.sh
drwxr-xr-x 2 root root 4096 Mar 23 21:25 kuangshen
drwxrw---x 2 www www 4096 Mar 23 12:46 www
[root@kuangshen home]# echo "i love kuangshen" >>f1 # 给f1文件中写入一些字符串!
[root@kuangshen home]# ls
f1 f2 f3 install.sh kuangshen www
[root@kuangshen home]# clear
[root@kuangshen home]# ll
total 36
-rw-r--r-- 2 root root 17 Mar 24 20:19 f1
-rw-r--r-- 2 root root 17 Mar 24 20:19 f2
lrwxrwxrwx 1 root root 2 Mar 24 20:18 f3 -> f1
-rw-r--r-- 1 root root 20078 Mar 4 16:48 install.sh
drwxr-xr-x 2 root root 4096 Mar 23 21:25 kuangshen
drwxrw---x 2 www www 4096 Mar 23 12:46 www
[root@kuangshen home]# cat f1 # 查看f1
i love kuangshen
[root@kuangshen home]# cat f2 # 查看f2
i love kuangshen
[root@kuangshen home]# cat f3 # 查看f3
i love kuangshen
删除f1之后,查看f2 和 f3 的区别

[root@kuangshen home]# rm -rf f1
[root@kuangshen home]# ls
f2 f3 install.sh kuangshen www
[root@kuangshen home]# cat f2 # f2 硬链接还在
i love kuangshen
[root@kuangshen home]# cat f3 # f3(软连接、符号连接)快捷方式失效!
cat: f3: No such file or directory

浙公网安备 33010602011771号