4.文件系統
本章同步視頻:https://edu.51cto.com/sd/e4874
4.5 文件系統管理
4.5.1 df - report file system disk space usage
-h, --human-readable print sizes in human readable format (e.g., 1K 234M 2G)
-H, --si likewise, but use powers of 1000 not 1024
-i, --inodes list inode information instead of block usage
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/rhel-root 10229760 4194692 6035068 42% /
/dev/mapper/rhel-home 2037760 33032 2004728 2% /home
/dev/sda1 508588 121208 387380 24% /boot
[root@localhost ~]# df -h #以可讀的方式顯示,即GB
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 9.8G 4.1G 5.8G 42% /
/dev/mapper/rhel-home 2.0G 33M 2.0G 2% /home
/dev/sda1 497M 119M 379M 24% /boot
[root@localhost ~]# df -H #以1000換算
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 11G 4.3G 6.2G 42% /
/dev/mapper/rhel-home 2.1G 34M 2.1G 2% /home
/dev/sda1 521M 125M 397M 24% /boot
[root@localhost ~]# df -i #顯示inode使用情況
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/mapper/rhel-root 10240000 152278 10087722 2% /
/dev/mapper/rhel-home 2048000 31 2047969 1% /home
/dev/sda1 512000 328 511672 1% /boot
[root@localhost ~]# df -h /dev/sda1 #查看某一特定文件系統
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 497M 119M 379M 24% /boot
4.5.2 du - estimate file space usage
[root@localhost tmp]# du #查看當前目錄容量
[root@localhost tmp]# du --inode #查看當前目錄的inode使用情況
[root@localhost tmp]# du -s #顯示當前目錄的總量
[root@localhost tmp]# du -s /etc/ #顯示/etc目錄的總量
本章同步視頻:https://edu.51cto.com/sd/e4874
4.5.3 ln - make links between files
ln [OPTION]... [-T] TARGET LINK_NAME
-s :如果不加任何參數就進行連結,那就是hard link,至於 -s 就是symbolic link
-f :如果 目標檔 存在時,就主動的將目標檔直接移除後再建立!
[root@localhost tmp]# ls #查看當前文件
dir mbr mbr.l passwd root test
[root@localhost tmp]# ln mbr mbr.l #建立硬鏈接
[root@localhost tmp]# ll -i mbr* #查看源文件和硬鏈接
7562 -rw-r--r--. 2 root root 512 Mar 18 21:57 mbr
7562 -rw-r--r--. 2 root root 512 Mar 18 21:57 mbr.l
[root@localhost tmp]# rm -f mbr #刪除源文件
-rw-r--r--. 1 root root 512 Mar 18 21:57 mbr.l
lrwxrwxrwx. 1 root root 3 Mar 20 12:23 mbr.s -> mbr
[root@localhost tmp]# cat mbr.l #硬鏈接仍可打開
[root@localhost tmp]# ln dir dir.l
ln: ‘dir’: hard link not allowed for directory
[root@localhost tmp]# ln -s mbr mbr.s
[root@localhost tmp]# ll -i mbr*
7562 -rw-r--r--. 2 root root 512 Mar 18 21:57 mbr
7562 -rw-r--r--. 2 root root 512 Mar 18 21:57 mbr.l
7595 lrwxrwxrwx. 1 root root 3 Mar 20 12:23 mbr.s -> mbr
l 當來源檔被刪除之後,symbolic link 就會失效。
[root@localhost tmp]# rm -f mbr #刪除源文件
-rw-r--r--. 1 root root 512 Mar 18 21:57 mbr.l
lrwxrwxrwx. 1 root root 3 Mar 20 12:23 mbr.s -> mbr
[root@localhost tmp]# cat mbr.s #軟連接無法打開
cat: mbr.s: No such file or directory
l Symbolic Link 與 Windows 的快捷方式可以給他劃上等號。
[root@localhost tmp]# touch hard
-rw-r--r--. 1 root root 0 Mar 20 12:42 hard
[root@localhost tmp]# ln -s hard hard.s
-rw-r--r--. 1 root root 0 Mar 20 12:42 hard
[root@localhost tmp]# ln hard hard.l
[root@localhost tmp]# ll hard*
-rw-r--r--. 2 root root 0 Mar 20 12:42 hard
-rw-r--r--. 2 root root 0 Mar 20 12:42 hard.l
lrwxrwxrwx. 1 root root 4 Mar 20 12:42 hard.s -> hard
#建立一個硬鏈接,源文件和硬鏈接的鏈接數+1,軟鏈接的鏈接數不增加。
[root@localhost tmp]# mkdir dir
[root@localhost tmp]# ll -d dir
drwxr-xr-x. 2 root root 6 Mar 20 12:36 dir
[root@localhost tmp]# ll -a dir
drwxr-xr-x. 2 root root 6 Mar 20 12:36 .
drwxrwxrwt. 9 root root 4096 Mar 20 12:36 ..
[root@localhost tmp]# mkdir dir/dir1
[root@localhost tmp]# ll -d dir
drwxr-xr-x. 3 root root 17 Mar 20 12:38 dir
[root@localhost tmp]# touch dir/aaa
[root@localhost tmp]# ll -d dir/
drwxr-xr-x. 3 root root 27 Mar 20 12:39 dir/
[root@localhost tmp]# mkdir dir/dir1/dir2
[root@localhost tmp]# ll -d dir/
drwxr-xr-x. 3 root root 27 Mar 20 12:39 dir/
#創建一個“孫”目錄,“爺”目錄的鏈接數不會增加,但父目錄的鏈接數會+1。