linux文件处理命令(链接)ln
ln [原文件] [目标文件]
-s //生成软连接
//生成硬链接
eg: [root@localhost ~]# ln -s h5 /tmp/h5.soft
[root@localhost ~]# ln h5 /tmp/h5.hard
[root@localhost ~]# ls -l
total 12
-rw-------. 1 root root 1462 Jan 19 20:27 anaconda-ks.cfg
-rw-r--r--. 2 root root 0 Jan 22 14:08 h5
drwxr-xr-x. 2 root root 4096 Jan 20 18:15 hello
drwxr-xr-x. 2 root root 4096 Jan 20 18:16 k1
[root@localhost ~]# ls -l /tmp
total 0
-rw-r--r--. 2 root root 0 Jan 22 14:08 h5.hard
lrwxrwxrwx. 1 root root 2 Jan 22 15:11 h5.soft -> h5
[root@localhost ~]#
软连接特性
相当于快捷方式,可通过软连接找到原文件
eg: [root@localhost ~]# ln -s h5 /tmp/h5.soft
[root@localhost ~]# ls -l
-rw-r--r--. 2 root root 0 Jan 22 14:08 h5
[root@localhost ~]# ls -l /tmp
lrwxrwxrwx. 1 root root 2 Jan 22 15:11 h5.soft -> h5
如上所示,软连接的权限均为rwx,都可以对其进行操作,因为它只是一个链接,真正操作的是原文件
硬链接特性
硬链接不同于软连接,它相当于copy又有别于copy,原文件与硬链接内容相同且同步。
如下
[root@localhost ~]# ln h5 /tmp/h5.hard
[root@localhost ~]# ls -l
-rw-r--r--. 2 root root 0 Jan 22 14:08 h5
[root@localhost ~]# ls -l /tmp
-rw-r--r--. 2 root root 0 Jan 22 14:08 h5.hard
[root@localhost ~]#
注意事项
- 硬链接不可跨分区,而软连接可以
- 硬链接的i值和原文件相同而软连接不同
[root@localhost ~]# ls -i /root/h5 /tmp/h5.hard /tmp/h5.soft
524301 /root/h5 524301 /tmp/h5.hard 393218 /tmp/h5.soft
[root@localhost ~]#