Linux system command: the difference between du and df!

du and df are two commonly used Linux system commands to view disk space usage, but their functions and outputs are slightly different.

  1. du Command:
    The du command is used to count the disk usage of a file or directory. It can recursively traverse directories and calculate the size of all files and subdirectories within. The output of the du command is the actual disk space used, and the unit can be bytes, kilobytes, megabytes, etc.

    For example, the following command will display the disk usage of all files and subdirectories in the current directory:

    du -sh *

    -soption means to display only the total size, -hoption means to display the size in a human readable format.

  2. df command:
    The df command is used to report the disk space usage of the file system. It displays information such as total capacity, used space, free space, and mount points of mounted file systems. The df command outputs statistics at the file system level.

    For example, the following command will display the space usage of all mounted filesystems on the current system:

    df -h

    -hoption indicates to display the size in a human readable format.

Summary:
The du command is used to calculate the disk usage of a file or directory, and the output is the actual disk space used. The df command is used to report the disk space usage of the file system, and the output is the file system level statistics. They all provide different levels of disk space information, which can be selected according to needs.

Guess you like

Origin blog.csdn.net/tiansyun/article/details/131497088
Recommended