本文为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