硬连接:当系统要读取一个文件时,会先读inode信息,而后再根据inode中的信息到块区域将数据取出来。而硬连接是直接再创建一个inode连接到文件放置的块区域。即创建硬连接时该文件内容没有变化,只是增长了一个指向这个文件的inode,并不会额外占用磁盘空间。node
硬连接不支持对目录作连接,只支持对文件作连接windows
[root@localhost ~]# ln 1.txt 1_heard.txt
[root@localhost ~]# ln -s 1.txt 1_sorft.txt
[root@localhost ~]# ls -l 总用量 32 drwxr-xr-x. 3 root root 45 10月 26 16:11 111 -rw-r--r--. 1 root root 0 10月 26 15:54 111.12.txt -rw-r--r--. 2 root root 391 10月 30 15:10 1_heard.txt lrwxrwxrwx. 1 root root 5 10月 30 15:06 1_sorft.txt -> 1.txt [root@localhost ~]# ls -i 33584735 111 33575033 1_sorft.txt 33575034 2.txt 33574987 anaconda-ks.cfg 33584737 111.12.txt 33575035 1.txt 33584734 3.txt 33575006 anaconda-ks.cfg.1 33575035 1_heard.txt 33584733 1.txt~ 33584736 3.txt~ 33575036 windows.txt
[root@localhost ~]# rm 1.txt rm:是否删除普通文件 "1.txt"?y [root@localhost ~]# ls -l 总用量 28 drwxr-xr-x. 3 root root 45 10月 26 16:11 111 -rw-r--r--. 1 root root 0 10月 26 15:54 111.12.txt -rw-r--r--. 1 root root 391 10月 30 15:10 1_heard.txt lrwxrwxrwx. 1 root root 5 10月 30 15:06 1_sorft.txt -> 1.txt
[root@localhost ~]# ls -i 1_heard.txt 33575035 1_heard.txt
[root@localhost ~]# ln 111 hf11 在硬连接指向目录的时候,会提示错误 ln: "111": 不容许将硬连接指向目录
[root@localhost ~]# df -h 文件系统 容量 已用 可用 已用% 挂载点 /dev/sda3 18G 1.1G 17G 6% / devtmpfs 483M 0 483M 0% /dev tmpfs 493M 0 493M 0% /dev/shm tmpfs 493M 6.7M 486M 2% /run tmpfs 493M 0 493M 0% /sys/fs/cgroup /dev/sda1 197M 109M 88M 56% /boot tmpfs 99M 0 99M 0% /run/user/0 [root@localhost ~]# ls -i /boot/ 71 config-3.10.0-514.el7.x86_64 67 grub 131136 grub2 76 initramfs-0-rescue-513f8b3950084e768a99df3a6cd3d9e6.img 75 initramfs-3.10.0-514.el7.x86_64.img 189445 initramfs-3.10.0-514.el7.x86_64kdump.img 74 initrd-plymouth.img 72 symvers-3.10.0-514.el7.x86_64.gz 70 System.map-3.10.0-514.el7.x86_64 77 vmlinuz-0-rescue-513f8b3950084e768a99df3a6cd3d9e6 73 vmlinuz-3.10.0-514.el7.x86_64 [root@localhost ~]# ln /boot/config-3.10.0-514.el7.x86_64 /tmp/conifg.1 ln: 没法建立硬连接"/tmp/conifg.1" => "/boot/config-3.10.0-514.el7.x86_64": 无效的跨设备链接