一、符号链接 symbolic link [root@localhost ~]# echo 222 > /file222.txt [root@sxl1 ~]# ln -s /file222.txt /boot/s-file222.txt [root@sxl1 ~]# ll -i /file222.txt /boot/s-file222.txt 41 lrwxrwxrwx 1 root root 12 Jan 10 16:19 /boot/s-file222.txt -> /file222.txt 18 -rw-r--r-- 1 root root 4 Jan 10 16:18 /file222.txt 二、硬链接 [root@localhost ~]# echo 111 > /file111.txt [root@localhost ~]# ln /file111.txt /etc [root@localhost ~]# ln /file111.txt /etc/h-111.txt [root@localhost ~]# ll -i /file111.txt /etc/file111.txt /etc/h-111.txt 17 -rw-r--r-- 3 root root 4 Jan 10 16:16 /etc/file111.txt 17 -rw-r--r-- 3 root root 4 Jan 10 16:16 /etc/h-111.txt 17 -rw-r--r-- 3 root root 4 Jan 10 16:16 /file111.txt 注:硬链接 1. 不能跨分区 2. 不支持目录做硬链接 3. 系统可以给目录做硬链接 4. 上面红色数字:是硬链接的个数 [root@localhost home]# ln /home/ /mnt ln: “/home/”: 不允许将硬链接指向目录
文件链接方式 :
符号连接(软链接)
ln -s /tmp/passwd /home/
硬链接
ln /tmp/passwd /tmp/passwd.link
符号连接(软链接)
ln -s /tmp/passwd /home/
硬链接
ln /tmp/passwd /tmp/passwd.link
区别:
1.命令相同 参数不同
软链接在创建必须绝对路径
硬链接都可以
2.硬链接的权限和源文件完全一致
软链接的链接文件权限永远是777 和源文件权限不同
3.硬链接可以删除,移动源文件
软链接不可以删除,移动源文件
4.软链接inode和源文件不同
硬链接的inode的源文件相同
5.软链接可以对目录生效
硬链接之可以对文件操作
6.软链接可以跨文件系统
硬链接不可以跨文件系统
unlink 链接文件名 取消链接