本文為joshua317原創文章,轉載請注明:轉載自joshua317博客 https://www.joshua317.com/article/159
一、簡介
Linux里的df(英文全拼:disk free) 命令用於顯示目前在 Linux 系統上的文件系統磁盤使用情況統計;通常我們可以用來查看磁盤被占用多少空間、還剩多少空間等信息。
二、格式說明
df [OPTION]... [FILE]...
df [選項]... [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 pseudo, duplicate, inaccessible file systems
-B, --block-size=SIZE scale sizes by SIZE before printing them; e.g.,
'-BM' prints sizes in units of 1,048,576 bytes;
see SIZE format below
--direct show statistics for a file instead of mount point
--total produce a grand total
-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)
--output[=FIELD_LIST] use the output format defined by FIELD_LIST,
or print all fields if FIELD_LIST is omitted.
-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
Display values are in units of the first available SIZE from --block-size,
and the DF_BLOCK_SIZE, BLOCK_SIZE and BLOCKSIZE environment variables.
Otherwise, units default to 1024 bytes (or 512 if POSIXLY_CORRECT is set).
SIZE is an integer and optional unit (example: 10M is 10*1024*1024). Units
are K, M, G, T, P, E, Z, Y (powers of 1024) or KB, MB, ... (powers of 1000).
FIELD_LIST is a comma-separated list of columns to be included. Valid
field names are: 'source', 'fstype', 'itotal', 'iused', 'iavail', 'ipcent',
'size', 'used', 'avail', 'pcent', 'file' and 'target' (see info page).
三、選項說明
-a 顯示所有系統文件
-B <塊大小> 指定顯示時的塊大小
-h 以更易讀的方式顯示
-H 等於"-h",以1000字節為換算單位來顯示,即是1K=1000,而不是1K=1024
-i 顯示inode信息
-k 指定塊大小為1KB
-l 只顯示本地文件系統
-P --portability 使用 POSIX 輸出格式
-t <文件系統類型> 只顯示指定類型的文件系統
-T 輸出時顯示文件系統類型
-x --exclude-type=TYPE 限制列出文件系統不要顯示 TYPE
-v (忽略)
-- -sync 在取得磁盤使用信息前,先執行sync命令
四、命令功能
用來查看linux服務器的文件系統的磁盤空間占用情況。顯示指定磁盤文件的可用空間。如果沒有文件名被指定,則所有當前被掛載的文件系統的可用空間將被顯示。默認情況下,磁盤空間將以 1KB 為單位進行顯示,除非環境變量 POSIXLY_CORRECT 被指定,那樣將以512字節為單位進行顯示
五、常見用法
5.1 顯示文件系統的磁盤分區使用情況
# df
Filesystem 1K-blocks Used Available Use% Mounted on
devtmpfs 3993820 0 3993820 0% /dev
tmpfs 4004328 24 4004304 1% /dev/shm
tmpfs 4004328 660 4003668 1% /run
tmpfs 4004328 0 4004328 0% /sys/fs/cgroup
/dev/vda1 51473868 23393272 25757476 48% /
tmpfs 800868 0 800868 0% /run/user/0
5.2 以更易讀的方式顯示文件系統的磁盤分區使用情況
# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 3.9G 0 3.9G 0% /dev
tmpfs 3.9G 24K 3.9G 1% /dev/shm
tmpfs 3.9G 660K 3.9G 1% /run
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/vda1 50G 23G 25G 48% /
tmpfs 783M 0 783M 0% /run/user/0
5.3 顯示指定文件所在分區的磁盤使用情況
# df /home -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 50G 23G 25G 48% /
5.4 顯示文件類型為ext4的磁盤使用情況
# df -ht ext4
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 50G 23G 25G 48% /
5.5 顯示inode信息而非塊使用量
# df -i
Filesystem Inodes IUsed IFree IUse% Mounted on
devtmpfs 998455 332 998123 1% /dev
tmpfs 1001082 7 1001075 1% /dev/shm
tmpfs 1001082 465 1000617 1% /run
tmpfs 1001082 16 1001066 1% /sys/fs/cgroup
/dev/vda1 3276800 180677 3096123 6% /
tmpfs 1001082 1 1001081 1% /run/user/0
5.6 列出文件系統的類型
# df -T
Filesystem Type 1K-blocks Used Available Use% Mounted on
devtmpfs devtmpfs 3993820 0 3993820 0% /dev
tmpfs tmpfs 4004328 24 4004304 1% /dev/shm
tmpfs tmpfs 4004328 660 4003668 1% /run
tmpfs tmpfs 4004328 0 4004328 0% /sys/fs/cgroup
/dev/vda1 ext4 51473868 23400284 25750464 48% /
tmpfs tmpfs 800868 0 800868 0% /run/user/0
5.7 只顯示本地文件系統
# df -l
Filesystem 1K-blocks Used Available Use% Mounted on
devtmpfs 3993820 0 3993820 0% /dev
tmpfs 4004328 24 4004304 1% /dev/shm
tmpfs 4004328 660 4003668 1% /run
tmpfs 4004328 0 4004328 0% /sys/fs/cgroup
/dev/vda1 51473868 23400568 25750180 48% /
tmpfs 800868 0 800868 0% /run/user/0
說明:-l參數只顯示本地的分區的磁盤空間使用率,如果服務器nfs了遠程服務器的磁盤,那么在df上加上-l后系統顯示的是過濾nsf驅動器后的結
本文為joshua317原創文章,轉載請注明:轉載自joshua317博客 https://www.joshua317.com/article/159