Click the blue text to follow us

1. Introduction
The df command (full English: display free disk space) is used to display or view the space usage of file systems (or disks), including total capacity, used space, available space, usage rate, and mount points.
2. Syntax
Syntax: df [options]… [file]…
Parameter Description:
|
Parameter |
Parameter Description |
|
-a, –all |
Display all file systems, including virtual file systems (such as proc, sysfs) |
|
-B, –block-size=SIZE |
Specify the display unit (e.g., -BK=KB, -BM=MB, -BG=GB) |
|
-h, –human-readable |
Display in a human-readable format (automatically converts units: K, M, G, T based on 1024) |
|
-H, –si |
Similar to -h, but uses 1000 as the conversion unit (according to SI standards) |
|
-i, –inodes |
Display inode usage (instead of disk space) |
|
-k |
Display in 1KB units (default unit) |
|
-m |
Display in 1MB units (supported by some systems) |
|
-l, –local |
Only display local file systems (exclude network file systems such as NFS) |
|
–no-sync |
Do not call sync before obtaining information (default behavior) |
|
–sync |
Call sync before obtaining information (ensures data is up to date) |
|
–total |
Display total information |
|
-T, –print-type |
Display file system type |
|
-t, –type=TYPE |
Only display file systems of the specified type (e.g., ext4, xfs) |
|
-P, –portability |
Use a POSIX compatible output format (avoids line break issues) |
|
-x, –exclude-type=TYPE |
Exclude specified file system types |
|
–output[=FIELD_LIST] |
Customize output fields (e.g., source,fstype,size,pcent) |
|
–help |
Display this help information and exit |
|
–version |
Display version information and exit |
3. Practical Examples
[root@app01 ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
devtmpfs 914424 0 914424 0% /dev
tmpfs 931500 0 931500 0% /dev/shm
tmpfs 931500 10432 921068 2% /run
tmpfs 931500 0 931500 0% /sys/fs/cgroup
/dev/mapper/rootvg-lv_root 26193412 4573168 21620244 18% /
/dev/sda1 1038336 189248 849088 19% /boot
/dev/mapper/rootvg-lv_app 31441920 3723864 27718056 12% /app
tmpfs 186304 12 186292 1% /run/user/42
tmpfs 186304 0 186304 0% /run/user/0
Description:
Filesystem: The name or identifier of the file system.
1K-blocks: The total capacity of the file system, in 1KB units, i.e., the total size of the file system.
Used: The capacity used in the file system, in 1KB units.
Available: The capacity available in the file system, in 1KB units.
Use%: The percentage of used capacity relative to the total capacity.
Mounted on: The directory or location where the file system is mounted.
1. The -h option displays disk space usage in a human-readable format.
[root@app01 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 893M 0 893M 0% /dev
tmpfs 910M 0 910M 0% /dev/shm
tmpfs 910M 11M 900M 2% /run
tmpfs 910M 0 910M 0% /sys/fs/cgroup
/dev/mapper/rootvg-lv_root 25G 4.4G 21G 18% /
/dev/sda1 1014M 185M 830M 19% /boot
/dev/mapper/rootvg-lv_app 30G 3.6G 27G 12% /app
tmpfs 182M 12K 182M 1% /run/user/42
tmpfs 182M 0 182M 0% /run/user/0
This command parameter displays in a human-readable format, making it easier to read, with capacity units automatically converted (K, M, G, T, based on 1024).
2. The df command can also display the file system information for a specific file system or directory.
[root@app01 ~]# df /app
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/rootvg-lv_app 31441920 3723864 27718056 12% /app
[root@app01 app]# df /app/jdk
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/rootvg-lv_app 31441920 3723864 27718056 12% /app
3. The -i option displays inode information instead of block usage.
[root@app01 app]# df -i
Filesystem Inodes IUsed IFree IUse% Mounted on
devtmpfs 228606 398 228208 1% /dev
tmpfs 232875 1 232874 1% /dev/shm
tmpfs 232875 910 231965 1% /run
tmpfs 232875 16 232859 1% /sys/fs/cgroup
/dev/mapper/rootvg-lv_root 13103104 160828 12942276 2% /
/dev/sda1 524288 341 523947 1% /boot
/dev/mapper/rootvg-lv_app 15728640 1231 15727409 1% /app
tmpfs 232875 9 232866 1% /run/user/42
tmpfs 232875 1 232874 1% /run/user/0
Note:Sometimes when using the df -Th command to check the file system, you may find that there is sufficient available space, but files cannot be written. This may be due to the inode value being full.
Inodes contain metadata about files, specifically including the following:
* The number of bytes in the file
* The User ID of the file owner
* The Group ID of the file
* The read, write, and execute permissions of the file
* The timestamps, which include three types:
ctime indicates the last time the inode was modified,
mtime indicates the last time the file content was modified,
atime indicates the last time the file was accessed.
* The number of links, i.e., how many file names point to this inode
* The location of the file data blocks
4. Display all information
[root@app01 app]# df --total
Filesystem 1K-blocks Used Available Use% Mounted on
devtmpfs 914424 0 914424 0% /dev
tmpfs 931500 0 931500 0% /dev/shm
tmpfs 931500 10432 921068 2% /run
tmpfs 931500 0 931500 0% /sys/fs/cgroup
/dev/mapper/rootvg-lv_root 26193412 4573168 21620244 18% /
/dev/sda1 1038336 189248 849088 19% /boot
/dev/mapper/rootvg-lv_app 31441920 3723864 27718056 12% /app
tmpfs 186304 12 186292 1% /run/user/42
tmpfs 186304 0 186304 0% /run/user/0
total 62755200 8496724 54258476 14% -
Using the –total parameter to view the file system, we see an additional line at the end of the output (total), which shows the sum of each column.
5. Check the file system type
[root@app01 app]# df -T
Filesystem Type 1K-blocks Used Available Use% Mounted on
devtmpfs devtmpfs 914424 0 914424 0% /dev
tmpfs tmpfs 931500 0 931500 0% /dev/shm
tmpfs tmpfs 931500 10432 921068 2% /run
tmpfs tmpfs 931500 0 931500 0% /sys/fs/cgroup
/dev/mapper/rootvg-lv_root xfs 26193412 4573168 21620244 18% /
/dev/sda1 xfs 1038336 189248 849088 19% /boot
/dev/mapper/rootvg-lv_app xfs 31441920 3723864 27718056 12% /app
tmpfs tmpfs 186304 12 186292 1% /run/user/42
tmpfs tmpfs 186304 0 186304 0% /run/user/0
Using the -T parameter, you can see the type of each file system, which is the data in the second column (Type).
Note: When using the df command, you can combine parameters to see different output results; this is not shown here, but you can try it yourself to see the different outputs.
Long press the QR code to follow us


CSDN BlogδΈ¨Countless Stars in the Sky
https://blog.csdn.net/myself88129