硬鏈接
ls -i 查看文件inode 值 (同樣適用於df命令)
-d 只看文件夾屬性
-h 按單位顯示容量 (df命令中顯示容量)
文件系統硬鏈接、軟鏈接
ln命令可以創建硬鏈接
ln 源文件 目標文件 br/>例:
[root@localhost ~]# touch a.txt
[root@localhost ~]# ll a.txt
-rw-r--r--. 1 root root 0 12月 4 18:51 a.txt #鏈接數是1
[root@localhost ~]# ln a.txt a2.txt #創建硬鏈接br/>[root@localhost ~]# ll a.txt
-rw-r--r--. 2 root root 0 12月 4 18:51 a.txt #鏈接數變成2br/>[root@localhost ~]# ll a2.txt
-rw-r--r--. 2 root root 0 12月 4 18:51 a2.txt #鏈接數同樣爲2br/>[root@localhost ~]# vim a.txt
[root@localhost ~]# cat a.txtbr/>test inode or data
[root@localhost ~]# cat a2.txt
test inode or databr/>[root@localhost ~]# ls -i a.txt a2.txt
140007310 a2.txt 140007310 a.txt #inode值一樣br/>測試
[root@localhost ~]# rm -rf a.txt
[root@localhost ~]# cat a2.txt
test inode or data
[root@localhost ~]# ll a2.txt
-rw-r--r--. 1 root root 20 12月 4 18:57 a2.txt
[root@localhost ~]#
總結:硬鏈接的特點,不能跨分區,不能給文件夾創建。(也不知道有啥用)
軟鏈接
:相當於windows中的快捷方式
創建軟鏈接不會增加鏈接數
ln -s 源文件 鏈接名br/>例:
[root@localhost ~]# ln -s a2.txt as.txt
[root@localhost ~]# lsbr/>a2.txt as.txt
[root@localhost ~]# ll as.txt
lrwxrwxrwx. 1 root root 6 12月 4 19:08 as.txt -< a2.txt
例:
跨分區,跨文件夾
[root@localhost ~]# ln -s /boot/grub2/ grub2br/>[root@localhost ~]# ll
總用量 4br/>-rw-r--r--. 1 root root 21 12月 4 19:08 a2.txt
lrwxrwxrwx. 1 root root 6 12月 4 19:08 as.txt -< a2.txt
lrwxrwxrwx. 1 root root 12 12月 4 19:11 grub2 -< /boot/grub2/
[root@localhost ~]# ll -d grub2/
drwx------. 6 root root 104 11月 29 18:04 grub2/br/>例:
創建軟鏈接不會增加鏈接數
[root@localhost ~]# ll a2.txt
-rw-r--r--. 1 root root 21 12月 4 19:08 a2.txtbr/>[root@localhost ~]# ln -s a2.txt assas.txt
[root@localhost ~]# ll a2.txtbr/>-rw-r--r--. 1 root root 21 12月 4 19:08 a2.txt
實例:
服務器中小文件很多,導致硬盤有空間,但無法創建文件
inode數被用光
[root@localhost /]# df -i
文件系統 Inode 已用(I) 可用(I) 已用(I)% 掛載點
/dev/sda3 58510336 145977 58364359 1% /
devtmpfs 480727 387 480340 1% /dev
tmpfs 484369 6 484363 1% /dev/shm
tmpfs 484369 518 483851 1% /run
tmpfs 484369 13 484356 1% /sys/fs/cgroup
/dev/sda1 204800 328 204472 1% /boot
tmpfs 484369 17 484352 1% /run/user/42
tmpfs 484369 1 484368 1% /run/user/0