链接命令: ln
ln -s [原文件] [目标文件]
命令英文原意: link
功能描述: 生成链接文件
选项:-s 创建软链接
硬链接特征:
1. 拥有相同的 i 节点和存储 block 块, 可以看做是同一个文件
2. 可通过 i 节点识别
3. 不能跨分区
4. 不能针对目录使用
- [[email protected] ~]# ls
- anaconda-ks.cfg binaries binaries.tar.gz initial-setup-ks.cfg test123
- [[email protected] ~]# ln /root/anaconda-ks.cfg /tmp/ana.hard
- [[email protected] ~]# ls -i /root/anaconda-ks.cfg /tmp/ana.hard -- 两个文件的 i 节点是相同的
- 25165890 /root/anaconda-ks.cfg 25165890 /tmp/ana.hard
软链接特征:
1. 类似 Windows 快捷方式
2. 软链接拥有自己的 i 节点和 block 块, 但是数据块儿中只保存原文件的文件名和 i 节点号, 并没有实际的文件数据
3. 软链接的权限都为 777, 但是实际的权限需要看原文件的权限
4. 修改任意文件, 另一个都改变
5. 删除原文件, 软链接不能使用 (原文件必须写绝对路径, 否则原文件和目标文件必须在同一目录下)
- [[email protected] ~]# ls
- anaconda-ks.cfg binaries binaries.tar.gz initial-setup-ks.cfg test123 test3
- [[email protected] ~]# ln -s /root/test3 /tmp/test3.soft
- [[email protected] ~]# ln /root/test3 /tmp/test3.hard
- [[email protected] ~]# ll -i
总用量 20172
25165890 -rw-------. 2 root root 2165 5 月 13 16:15 anaconda-ks.cfg
17070804 drwxr-xr-x. 14 501 games 175 6 月 17 2017 binaries
25288936 -rw-r--r--. 1 root root 20647102 6 月 22 2017 binaries.tar.gz
25165908 -rw-r--r--. 1 root root 2213 5 月 13 16:17 initial-setup-ks.cfg
8546987 drwxr-xr-x. 3 root root 19 6 月 15 16:59 test123
25708548 -rw-r--r--. 2 root root 0 6 月 16 11:15 test3
[[email protected] ~]# ll -i /tmp/
总用量 256
17070621 -rw-------. 1 root root 2165 6 月 15 16:22 ana
17071146 -rw-------. 1 root root 2165 5 月 13 16:15 anaconda-ks.cfg
25165890 -rw-------. 2 root root 2165 5 月 13 16:15 ana.hard
25521547 drwxr-xr-x. 3 root root 19 6 月 15 16:25 test1
8388685 drwxr-xr-x. 3 root root 19 6 月 15 16:24 test3
25708548 -rw-r--r--. 2 root root 0 6 月 16 11:15 test3.hard
17071129 lrwxrwxrwx. 1 root root 11 6 月 16 11:16 test3.soft -> /root/test3
- [[email protected] ~]# echo 111>> /root/test3
- [[email protected] ~]# cat /tmp/test3.soft
- 111
- [[email protected] ~]# cat /tmp/test3.hard
- 111
- [[email protected] ~]# echo 2222>> /tmp/test3.soft
- [[email protected] ~]# cat /tmp/test3.hard
- 111
- 2222
- [[email protected] ~]# cat /root/test3
- 111
- 2222
- [[email protected] ~]# echo 3333>> /tmp/test3.hard
- [[email protected] ~]# cat /root/test3
- 111
- 2222
- 3333
- [[email protected] ~]# cat /tmp/test3.soft
- 111
- 2222
- 3333
- [[email protected] ~]# rm -rf /root/test3
- [[email protected] ~]# cat /tmp/test3.hard
- 111
- 2222
- 3333
- [[email protected] ~]# cat /tmp/test3.soft
cat: /tmp/test3.soft: 没有那个文件或目录
来源: http://www.bubuko.com/infodetail-3093961.html