du Directories Only: Complete Guide to Disk Usage Command in 2026


Efficient disk space management is a cornerstone of Linux system administration. Whether you are managing complex rust directories or cleaning up personal projects, the du (disk usage) command utility is your primary tool for identifying space hogs. This guide focuses on isolating directory-level data, helping you navigate your file system without the clutter of individual file listings. Modern developers and DevOps engineers use these techniques to maintain lean server environments and optimize storage across various directories and folders. Using the right flags ensures you focus on directories and folders rather than a messy list of individual files.
Introduction to du Command and Why It Matters
The du command, short for disk usage, summarizes the amount of disk space used by a set of files or directories. While tools like df show filesystem-wide statistics, du allows you to drill down into specific folders to see exactly where your storage is going. This is critical when you need to verify if your server has enough headroom for new deployments or migrations. Navigating through multiple levels of a directory of directories can be overwhelming without the right flags to filter the output. For those coming from other environments, think of this as the command line version of checking folder properties in windows directories or exploring xdg directories on a desktop Linux setup. Understanding how to list only directories helps you quickly identify which project or system component is consuming your quota.
Pain Points: Why Manual Directory Analysis is Tedious
Managing disk space often involves frustrating bottlenecks. System administrators frequently face the challenge of overwhelming output when running simple commands. Without the correct parameters, du provides too much data, making it impossible to see the 'ideal directories' for cleanup. This manual filtering is time consuming and leads to mistakes where critical system files might be touched. Similarly, startup founders face 'application submission' hurdles when launching products, where they must manually fill out data across dozens of sites. The pain is the same: manual, repetitive work that could be automated or filtered for better efficiency. Using tools to sync directories and automate submissions is the modern solution to these technical and administrative burdens.
Basic du Command Syntax and Options for du Directories
To use the du command effectively, you must understand its core syntax: du [OPTIONS] [FILE]. By default, running du without any arguments will list every single file and directory recursively, which is rarely what you want. Key flags include -h for human readable format, -s for a summary of the total, and -a to include files. If you are used to using ls to list only directories, you will find that du requires specific depth flags to provide a clean overview of your storage. Effectively using these flags is as important as knowing how to change directories in command prompt environments when you are navigating a new server.
How to List Only Directories with du (Step-by-Step)
- 1Open your terminal or command prompt and navigate to your target path.
- 2Run 'du -h --max-depth=1' to see the size of all immediate subdirectories. This is the most efficient way to list only directories at a specific level.
- 3To further filter, pipe the output to grep: 'du -h -d 1 | grep \"/$\"'. This ensures you glob directories only and ignore any loose files in the root.
- 4If you need to move between folders frequently, remember to use cd to change directories in command prompt before running your disk analysis.
- 5For a cleaner list only directories view, combine the summary flag with the target path: 'du -sh */'.
Human-Readable Output Formats
Raw block numbers are difficult to interpret. The -h flag is your best friend, as it automatically scales units to KB, MB, or GB. In 2026, most administrators prefer human readable output to quickly identify if a folder has reached several gigabytes. This is especially helpful when managing shared spaces like slack directories or complex build environments. For precise automation, you might prefer the raw byte count to sync directories across different servers without rounding errors. When you list only directories, having them in a readable format allows for faster decision making during a server crisis.
Excluding Files and Directories from du Output
- Use the --exclude flag to ignore specific patterns like logs or temporary files.
- Example: du -h --exclude='*.log' helps you focus on core application data.
- Ignore development dependencies in rust directories by excluding 'target' folders.
- Skip hidden system items by avoiding flags that would ls show hidden directories.
- The --exclude option supports wildcards, allowing you to filter out entire categories of data while you list only directories that matter.
Finding the Largest Directories
To find the biggest storage consumers, you must combine du with the sort command. Running 'du -h /path | sort -rh | head -n 10' provides a ranked list of the top 10 space hogs. This is a common task when performing a directory of directories audit. Using 'list directories r' (the recursive flag) ensures you don't miss hidden subfolders deep within the structure. This methodology is the gold standard for DevOps engineers who need to keep their production environments lean and efficient. Identification of these large folders is the first step toward effective system cleanup.
Advanced du Options for Power Users
Advanced users can leverage the -c flag to produce a grand total at the end of the output, which is useful for audit reports. If you are dealing with symbolic links, the -L flag ensures du follows the links to calculate the actual size of the linked content. For those managing modern Linux desktops, monitoring xdg directories ensures your user configuration isn't ballooning. Another powerful option is --apparent-size, which shows how much data is actually in the file, rather than how much space it takes on the physical disk (useful for sparse files). Understanding these capabilities helps map the du feature to your specific problem, whether it is debugging storage leaks or preparing for a data migration.
Practical du Command Examples and Scenarios
- 'du -sh */' - Get sizes of all subdirectories in the current folder quickly.
- 'du -h --max-depth=1 /home' - See directory sizes exactly one level deep for home folders.
- 'du --exclude=\"*.log\"' - Exclude log files from your total disk usage calculation.
- 'du -ah /var' - Use ls only directories logic? No, use this to show all files and directories in human readable sizes.
- 'du -h | sort -rh | head -n 10' - The classic one-liner to find the biggest storage users on your server.
Common du Command Mistakes and What's New in 2026
What's new in 2026? Modern versions of coreutils have improved performance for large filesystems, specifically benefiting those managing massive rust directories. However, common mistakes still trip up users. Forgeting the -h flag often results in unreadable raw byte counts. Users also confuse du with df; remember that du checks folder sizes while df checks the entire disk partition. Another trap is permissions. If you run du on a directory where you lack read access, you will get 'permission denied' errors, resulting in an incomplete and inaccurate total. Always use sudo if you need a comprehensive scan of the root directory.
Quick Reference: du Command Cheat Sheet
| Task | Command Line Example | Key Benefit |
|---|---|---|
| Summary of current folder | du -sh . | Quick overview of total size |
| Check subdirectories only | du -h --max-depth=1 | List only directories without file clutter |
| Find top 5 large folders | du -h | sort -rh | head -5 | Identifies space-consuming folders |
| Exclude specific types | du --exclude='*.mp4' | Filters out irrelevant large files |
| Show totals only | du -ch /path/to/dir | Provides a sum of multiple folders |
How do I use the du command to list only directories?+
Use 'du -h --max-depth=1' to see all folders at the current level without listing every single file inside them.
What's the difference between du and df commands?+
The du command measures file space usage at the directory level, while df (disk free) shows the amount of available and used space on the entire filesystem partition.
How can I exclude certain file types from du output?+
Use the --exclude flag. For example, 'du --exclude=\"*.tmp\"' will ignore all files ending in .tmp when calculating directory sizes.
How do I get du to show sizes in human-readable format?+
Simply add the -h flag to your command (e.g., du -h) to see sizes automatically scaled to KB, MB, and GB.
How do I find the largest directories using du?+
To find large folders, pipe the output to sort: 'du -h /path | sort -rh | head -n 10'.