Mastering Disk Space: A Beginner's Guide to df and du

Have you ever received a cryptic "No space left on device" error while trying to save a file, or wondered why your Linux system is running slowly even though you just installed it? You're not alone. Many new users find themselves staring at a full drive with no idea where the storage went. Understanding how to check and manage disk space is one of the first superpowers you'll gain in Linux, turning confusion into control.

Managing disk space is essential for keeping your Linux system healthy and responsive. When drives fill up, applications can crash, updates may fail, and the entire system can become sluggish. For beginners, knowing how to read disk usage helps you troubleshoot issues before they become critical, plan where to store large files, and understand how different partitions contribute to your total storage. Mastering these basics ensures you stay in charge of your digital environment rather than letting hidden files take over.

Step-by-Step Walkthrough

  • Step 1: Get a High-Level View with df
    The df command stands for "disk free" and displays information about your mounted file systems, such as hard drives and partitions. By default, the output shows sizes in small blocks that are difficult to interpret. To make the data readable, always use the human-readable flag -h. This converts numbers into familiar units like gigabytes (G) or megabytes (M). Run this command in your terminal:

    df -h
    

    You will see a table with columns like Filesystem, Size, Used, Avail, and Use%. Focus on the Use% column to identify drives that are nearing capacity. If you see a partition at 100%, that is likely the source of your storage problems.

  • Step 2: Measure Folder Sizes with du
    While df tells you how full the drive is, it doesn't tell you which folders are using that space. That is where du (disk usage) comes in. This command calculates the size of files and directories recursively. To check the total size of your home directory without overwhelming the terminal with a list of every single file, use the summarize flag -s along with -h. Execute the following to see your home folder size:

    du -sh ~
    

    The tilde ~ represents your user's home directory. This command gives you a quick snapshot of how much space your personal files, documents, and downloads occupy. If this number is unexpectedly high, you know you need to investigate further within your home folder.

  • Step 3: List Subdirectories to Find Space Hogs
    Once you identify a large directory, you need to drill down to find the specific folders consuming the most space. You can limit the depth of the output to avoid seeing thousands of lines. Using --max-depth=1 shows only the immediate subdirectories within the path you specify. This helps you spot large categories like "Videos" or "Downloads" at a glance. Try this command to list the top-level folders in your home directory:

    du -h --max-depth=1 ~
    

    Review the output from bottom to top, as du typically lists smaller items first. Look for lines with large values at the end of the list. This approach allows you to zero in on problem areas quickly without waiting for a full recursive scan of every file on your system.

  • Step 4: Check System Logs and Temporary Files
    Sometimes, user folders are fine, but system files have grown out of control. A common culprit is the log directory, which can accumulate massive text files over time. You can check the size of individual log files using a wildcard pattern. This technique helps you determine if old logs need to be cleaned up to free up space. Run this command to inspect log file sizes:

    du -sh /var/log/*
    

    The asterisk * acts as a wildcard that matches every file inside /var/log. If you see specific files taking up gigabytes of space, you may have found the reason for your low disk warning. Always verify what a file is before removing it, as some logs are necessary for system operation.

Common Beginner Mistakes to Avoid

  • Forgetting the -h flag: Without this flag, output displays in 1K blocks, making it nearly impossible to gauge actual storage usage quickly.
  • Running du without limits: Using du -ah / scans every file on the system and can take a very long time, slowing down your computer while it processes data.
  • Confusing df and du: Remember that df checks partitions and drives, while du checks folders and files inside those drives. Using the wrong tool leads to frustration.
  • Deleting system files blindly: Never delete files in directories like /usr, /lib, or /bin just to free up space, as this can break your operating system. Focus on user data and temporary files first.

Conclusion

Learning to read disk space with df and du empowers you to maintain a clean, efficient Linux system without guessing where your storage goes. With these commands in your toolkit, you can proactively manage partitions, locate large files, and prevent storage-related errors before they disrupt your workflow. For more hands-on Linux tutorials and expert support, check out Solv-IT.