df - macOS


Overview

The df command (short for “disk free”) is used to display the amount of available disk space for file systems on which the current user can perform operations. It is commonly employed to monitor the disk usage and manage space efficiently, especially in environments where resources are shared or limited.

Syntax

The basic syntax of the df command is:

df [options] [file ...]
  • [options]: Flags that modify the command’s behavior.
  • [file …]: One or more file names to check specific file systems.

Options/Flags

  • -h, –human-readable: Display sizes in power of 1024 (e.g., 1K, 234M, 2G).
  • -H, –si: Display sizes in powers of 1000 instead of 1024.
  • -a, –all: Include dummy file systems in the output.
  • -i, –inodes: List inode information instead of block usage.
  • -k: Use 1024-byte blocks. This is the default on macOS.
  • -l, –local: Limit the listing to local file systems.
  • -r, –print-type: Display file system type.
  • -t [fs], –type=[fs]: Limit output to file systems of type [fs].
  • –total: Produce a grand total.

Examples

Below are several examples of how to use df:

  1. Basic Usage: Display disk space usage of all file systems.

    df
    
  2. Human-Readable Format: Show the disk space in an easy-to-read format.

    df -h
    
  3. Check Specific File System: Display space related to a specific device.

    df /dev/disk1s1
    
  4. Show Inode Information: Useful for checking the number of free inodes.

    df -i
    
  5. Total Disk Usage: Print a summary of total used and available space.

    df --total
    

Common Issues

  • No Permissions: Users may encounter permission errors when trying to view file systems they are not allowed to access.
    • Solution: Run df using sudo for administrative privileges.
  • Misinterpretation of Output: By default, space is shown in 1-block increments. This can be misleading without the -h or -H flags.
    • Solution: Always use -h for clarity.

Integration

The df command can be used in conjunction with other commands for powerful disk management and monitoring, such as:

df -h | grep '/dev' # Display usage of just mounted devices
watch df -h        # Continuously monitor disk space usage
  • du: Display disk usage statistics for files and directories.
  • mount: Show or attach file systems.
  • fs_usage: Monitor file system activity in real-time.

For further details and documentation on file management in macOS, refer to official macOS file system documentation or manpage (man df).