Linux 中檢查磁碟空間的 12 個有用的 df 命令

語言: CN / TW / HK

點選進入“PHP開源社群”    

免費獲取進階面試、文件、影片資源

1. 檢查檔案系統磁碟空間使用情況

這 df 命令顯示檔案系統上的裝置名稱、總塊數、總磁碟空間、已用磁碟空間、可用磁碟空間和掛載點資訊。

[[email protected] ~]# df

Filesystem 1K-blocks Used Available Use% Mounted on
/dev/cciss/c0d0p2 78361192 23185840 51130588 32% /
/dev/cciss/c0d0p5 24797380 22273432 1243972 95% /home
/dev/cciss/c0d0p3 29753588 25503792 2713984 91% /data
/dev/cciss/c0d0p1 295561 21531 258770 8% /boot
tmpfs 257476 0 257476 0% /dev/shm

2. 顯示所有檔案系統磁碟空間使用資訊

與上面相同,但它還顯示虛擬檔案系統的資訊以及所有檔案系統磁碟使用情況及其記憶體使用情況。

[[email protected] ~]# df -a

Filesystem 1K-blocks Used Available Use% Mounted on
/dev/cciss/c0d0p2 78361192 23186116 51130312 32% /
proc 0 0 0 - /proc
sysfs 0 0 0 - /sys
devpts 0 0 0 - /dev/pts
/dev/cciss/c0d0p5 24797380 22273432 1243972 95% /home
/dev/cciss/c0d0p3 29753588 25503792 2713984 91% /data
/dev/cciss/c0d0p1 295561 21531 258770 8% /boot
tmpfs 257476 0 257476 0% /dev/shm
none 0 0 0 - /proc/sys/fs/binfmt_misc
sunrpc 0 0 0 - /var/lib/nfs/rpc_pipefs

3. 以人類可讀的格式顯示磁碟空間使用情況

你有沒有注意到,上面的命令以位元組為單位顯示資訊,根本不可讀,因為我們習慣於以兆位元組、千兆位元組等形式讀取大小,這樣很容易理解和記憶。

這df命令提供了一個選項來顯示尺寸Human Readable格式通過使用'-h'(以人類可讀的格式列印結果(例如,1K 2M 3G))。

[[email protected] ~]# df -h

Filesystem Size Used Avail Use% Mounted on
/dev/cciss/c0d0p2 75G 23G 49G 32% /
/dev/cciss/c0d0p5 24G 22G 1.2G 95% /home
/dev/cciss/c0d0p3 29G 25G 2.6G 91% /data
/dev/cciss/c0d0p1 289M 22M 253M 8% /boot
tmpfs 252M 0 252M 0% /dev/shm

4. 顯示 / home 檔案系統資訊

檢視唯一裝置的資訊/home人類可讀格式的檔案系統使用以下命令。

[[email protected] ~]# df -hT /home

Filesystem Type Size Used Avail Use% Mounted on
/dev/cciss/c0d0p5 ext3 24G 22G 1.2G 95% /home

5. 以位元組為單位顯示檔案系統資訊

顯示所有檔案系統資訊和使用情況1024-byte塊,使用選項'-k'(例如--block-size=1K)如下。

[[email protected] ~]# df -k

Filesystem 1K-blocks Used Available Use% Mounted on
/dev/cciss/c0d0p2 78361192 23187212 51129216 32% /
/dev/cciss/c0d0p5 24797380 22273432 1243972 95% /home
/dev/cciss/c0d0p3 29753588 25503792 2713984 91% /data
/dev/cciss/c0d0p1 295561 21531 258770 8% /boot
tmpfs 257476 0 257476 0% /dev/shm

6. 以MB為單位顯示檔案系統資訊

顯示所有檔案系統使用資訊MB(Mega Byte) 將該選項用作 -m。

[[email protected] ~]# df -m

Filesystem 1M-blocks Used Available Use% Mounted on
/dev/cciss/c0d0p2 76525 22644 49931 32% /
/dev/cciss/c0d0p5 24217 21752 1215 95% /home
/dev/cciss/c0d0p3 29057 24907 2651 91% /data
/dev/cciss/c0d0p1 289 22 253 8% /boot
tmpfs 252 0 252 0% /dev/shm

7. 以 GB 為單位顯示檔案系統資訊

顯示所有檔案系統統計資訊GB(Gigabyte) 將該選項用作 'df -h'。

[[email protected] ~]# df -h

Filesystem Size Used Avail Use% Mounted on
/dev/cciss/c0d0p2 75G 23G 49G 32% /
/dev/cciss/c0d0p5 24G 22G 1.2G 95% /home
/dev/cciss/c0d0p3 29G 25G 2.6G 91% /data
/dev/cciss/c0d0p1 289M 22M 253M 8% /boot
tmpfs 252M 0 252M 0% /dev/shm

8. 顯示檔案系統 inode

使用 -i 開關將顯示檔案系統的已使用 inode 數量及其百分比資訊。

[[email protected] ~]# df -i

Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/cciss/c0d0p2 20230848 133143 20097705 1% /
/dev/cciss/c0d0p5 6403712 798613 5605099 13% /home
/dev/cciss/c0d0p3 7685440 1388241 6297199 19% /data
/dev/cciss/c0d0p1 76304 40 76264 1% /boot
tmpfs 64369 1 64368 1% /dev/shm

9. 顯示檔案系統型別

如果您注意到上述所有命令輸出,您將看到結果中沒有提到Linux 檔案系統型別。要檢查系統的檔案系統型別,請使用選項 T。它將顯示檔案系統型別以及其他資訊。

[[email protected] ~]# df -T

Filesystem Type 1K-blocks Used Available Use% Mounted on
/dev/cciss/c0d0p2 ext3 78361192 23188812 51127616 32% /
/dev/cciss/c0d0p5 ext3 24797380 22273432 1243972 95% /home
/dev/cciss/c0d0p3 ext3 29753588 25503792 2713984 91% /data
/dev/cciss/c0d0p1 ext3 295561 21531 258770 8% /boot
tmpfs tmpfs 257476 0 257476 0% /dev/shm

10. 包括某些檔案系統型別

如果要顯示某些檔案系統型別,請使用 -t 選項。例如下面的命令只會顯示 ext3 檔案系統。

[[email protected] ~]# df -t ext3

Filesystem 1K-blocks Used Available Use% Mounted on
/dev/cciss/c0d0p2 78361192 23190072 51126356 32% /
/dev/cciss/c0d0p5 24797380 22273432 1243972 95% /home
/dev/cciss/c0d0p3 29753588 25503792 2713984 91% /data
/dev/cciss/c0d0p1 295561 21531 258770 8% /boot

11. 排除某些檔案系統型別

如果要顯示不屬於的檔案系統型別ext3鍵入使用選項作為 -x。例如,以下命令將只顯示除ext3。

[[email protected] ~]# df -x ext3

Filesystem 1K-blocks Used Available Use% Mounted on
tmpfs 257476 0 257476 0% /dev/shm

12. 顯示 df 命令的資訊。

使用'--help' 開關將顯示與df命令。

[[email protected]local ~]# df --help

Usage: df [OPTION]... [FILE]...
Show information about the file system on which each FILE resides,
or all file systems by default.

Mandatory arguments to long options are mandatory for short options too.
-a, --all include dummy file systems
-B, --block-size=SIZE use SIZE-byte blocks
-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
-k like --block-size=1K
-l, --local limit listing to local file systems
--no-sync do not invoke sync before getting usage info (default)
-P, --portability use the POSIX output format
--sync invoke sync before getting usage info
-t, --type=TYPE limit listing to file systems of type TYPE
-T, --print-type print file system type
-x, --exclude-type=TYPE limit listing to file systems not of type TYPE
-v (ignored)
--help display this help and exit
--version output version information and exit

SIZE may be (or may be an integer optionally followed by) one of following:
kB 1000, K 1024, MB 1000*1000, M 1024*1024, and so on for G, T, P, E, Z, Y.

Report bugs to <[email protected]>.

*宣告:本文於網路整理,版權歸原作者所有,如來源資訊有誤或侵犯權益,請聯絡我們刪除或授權事宜。

END

PHP開源社群

掃描關注  進入”PHP資料“

免費獲取進階

面試、文件、影片資源

點選“檢視原文”獲取更多