本文共 1330 字,大约阅读时间需要 4 分钟。
ln命令可以创建硬链接:
语法格式:ln 源文件 目标文件文件名1-》inode1-》blockA文件名2-》inode1-》blockA[root@localhost ~]# ln a.txt b.txt[root@localhost ~]# ll -i a.txt b.txt
36433003 -rw-r--r-- 2 root root 10 Feb 24 09:05 a.txt36433003 -rw-r--r-- 2 root root 10 Feb 24 09:05 b.txt[root@localhost ~]# rm -rf a.txt
[root@localhost ~]# cat b.txtaaaabbbb#源文件被删除,不影响链接文件的正常使用[root@localhost ~]# mkdir test
[root@localhost ~]# ln test/ 123ln: ‘test/’: hard link not allowed for directory#硬链接不能针对目录创建[root@localhost ~]# ln /boot/grub2/grub.cfg grub.cfg
ln: failed to create hard link ‘grub.cfg’ => ‘/boot/grub2/grub.cfg’: Invalid cross-device link#硬链接不允许跨分区创建总结: 硬链接特点,创建时,不能跨分区,不能给文件夹。软链接:相当于windows中的快捷方式
[root@localhost ~]# ln -s b.txt c.txt[root@localhost ~]# rm -rf b.txt[root@localhost ~]# cat c.txt
cat: c.txt: No such file or directory#源文件被删除,链接文件失效
[root@localhost ~]# ln -s test/ 123#能针对目录创建[root@localhost ~]# ln -s /boot/grub2/grub.cfg grub.cfg#能跨分区创建例:查看目录的链接数
[root@localhost ~]# ll -d test/drwxr-xr-x 2 root root 6 Feb 24 09:10 test/[root@localhost ~]# ll -di test/
50599109 drwxr-xr-x 2 root root 6 Feb 24 09:10 test/[root@localhost test]# ll -di .50599109 drwxr-xr-x 2 root root 6 Feb 24 09:10 .[root@localhost xuegod]# ll -di ..50599109 drwxr-xr-x 3 root root 19 Feb 24 09:23 ..转载于:https://blog.51cto.com/11638205/2048925