Tuesday, September 22, 2026

Linux df and du commands to manage and check disk space


1. df (Disk Free) — Check Filesystem Space

The df command shows the amount of disk space available on the entire file system.

  • Basic usage (Human-readable format):

    Bash
    df -h
    
    (The -h flag converts bytes into KB, MB, or GB for readability).

  • Show filesystem types along with space:

    Bash
    df -Th
    
    (Displays formats like ext4, tmpfs, xfs, etc.)

  • Check Inode usage (file count limits):

    Bash
    df -i
    
    (Useful if your disk says it has space, but you get "No space left on device" errors due to running out of inodes).

2. du (Disk Usage) — Check File & Directory Sizes

The du command estimates file and directory space usage, helping you find which specific folders are consuming your storage.

  • Check the size of a specific directory (human-readable):

    Bash
    du -sh /path/to/directory
    
    (The -s flag gives a summary total instead of listing every individual sub-file).

  • List sizes of all files and subfolders in the current directory:

    Bash
    du -h --max-depth=1
    
    (Helps you quickly see which sub-folder is taking up the most space).

  • Sort directories by size (largest first):

    Bash
    du -h --max-depth=1 | sort -hr
    
  • Show total size of everything in the current directory including a grand total:
    Bash
    du -ch
    


💡 Quick Summary Comparison

CommandFocusBest Used ForCommon Flag
dfFilesystem levelChecking overall hard drive / partition capacitydf -h
duDirectory levelFinding which specific folders or files are hogging spacedu -sh *