ln命令用于创建链接文件 格式为 ln [选项] 目标 是否添加 -s 参数,取决于创建的是软连接还是硬链接 ![参数][1] ##硬链接 vim 1.txt This is a hard link ln 1.txt 2.txt #为1.txt创建一个2.txt的硬链接 ![硬链接][2] ##软链接 在刚刚创建的2.txt的基础上创建软链接 ln -s 2.txt 3.txt [root@localhost ~]# ln -s 2.txt 3.txt [root@localhost ~]# ls -l -i total 16 33655349 -rw-r--r--. 1 root root 21 Jun 25 22:59 2.txt 33590735 lrwxrwxrwx. 1 root root 5 Jun 25 23:01 3.txt -> 2.txt [root@localhost ~]# cat 3.txt #查看软链接3.txt的内容 This is a hard link. [root@localhost ~]# rm -rf 2.txt #尝试删掉源文件 [root@localhost ~]# ls 1.csr 1.key 3.txt anaconda-ks.cfg [root@localhost ~]# cat 3.txt #查看软链接3.txt内容 cat: 3.txt: No such file or directory ls -l -i #查看 [1]: https://panfeng-biji.oss-cn-beijing.aliyuncs.com/img/image-20210625143638802.png [2]: https://panfeng-biji.oss-cn-beijing.aliyuncs.com/img/image-20210625150122391.png
最后修改:2021 年 10 月 07 日
如果觉得我的文章对你有用,欢迎打赏