Linux常用命令——链接命令

链接命令:ln

ln -s [原文件] [目标文件]
    命令英文原意:link
    功能描述:生成链接文件
        选项:-s 创建软链接

  硬链接特征:

  1.拥有相同的i节点和存储block块,可以看做是同一个文件

  2.可通过i节点识别

  3.不能跨分区

  4.不能针对目录使用

[root@localhost ~]# ls
anaconda-ks.cfg  binaries  binaries.tar.gz  initial-setup-ks.cfg  test123
[root@localhost ~]# ln /root/anaconda-ks.cfg /tmp/ana.hard
[root@localhost ~]# 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.删除原文件,软链接不能使用(原文件必须写绝对路径,否则原文件和目标文件必须在同一目录下)

[root@localhost ~]# ls
anaconda-ks.cfg  binaries  binaries.tar.gz  initial-setup-ks.cfg  test123  test3
[root@localhost ~]# ln -s /root/test3 /tmp/test3.soft
[root@localhost ~]# ln  /root/test3 /tmp/test3.hard
[root@localhost ~]# 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
[root@localhost ~]# 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
[root@localhost ~]# echo 111 >> /root/test3
[root@localhost ~]# cat /tmp/test3.soft 
111
[root@localhost ~]# cat /tmp/test3.hard 
111
[root@localhost ~]# echo 2222 >> /tmp/test3.soft 
[root@localhost ~]# cat /tmp/test3.hard 
111
2222
[root@localhost ~]# cat /root/test3 
111
2222
[root@localhost ~]# echo 3333 >> /tmp/test3.hard 
[root@localhost ~]# cat /root/test3
111
2222
3333
[root@localhost ~]# cat /tmp/test3.soft 
111
2222
3333
[root@localhost ~]# rm -rf /root/test3
[root@localhost ~]# cat /tmp/test3.hard 
111
2222
3333
[root@localhost ~]# cat /tmp/test3.soft 
cat: /tmp/test3.soft: 没有那个文件或目录

  

猜你喜欢

转载自www.cnblogs.com/Simon212/p/11028347.html