DU Command in Linux: powerful 2026 Guide

du command in linux

du command in linux is the most powerfule resource available in linux operating system for disk space management

If you are a system administrator needing to identify excessive server space use, a developer searching for lost storage space due to containers, or a cyber security analyst looking for oddities

then knowing how to read the disk space statistics using DU command will help protect you from significant loss and the risk of costly downtime through the acquisition of 100’s of hours of time saved by effectively utilizing Disk Space Statistics.

This comprehensive, article on the DU command in Linux covers all aspects including the most basic to recommending productive practices

tips for detecting and resolving real-world operational problems, methods for increasing performance, plus 20 frequently asked questions and answers.

Use this resource as an immediate guide if you find your /var/tmp storage gets filled at 2:00 AM every day!

Table of Contents

  1. What is DU Command in Linux?
  2. how to use du command in linux
  3. 25+ Essential DU Command Options
  4. 15 Basic DU Command Examples
  5. Advanced DU Command Techniques
  6. DU vs DF: Complete Comparison
  7. 10 Real-World DU Scenarios
  8. Troubleshooting DU Command Issues
  9. Performance Optimization for DU in linux
  10. 20 DU Aliases + 5 Powerful Scripts
  11. DU with Find, Sort, Watch
  12. DU Alternatives (ncdu, dust, etc.)
  13. Sysadmin Best Practices 2026
  14. 25 FAQs: DU Command in Linux

What is DU Command in Linux?

The du command in linux, is a method of determining how much storage space is consumed by files and directories, unlike the df command which shows the amount of space consumed at the filesystem level (the total amount of storage space available)

The DU command traverses directories in a recursive manner through a hierarchy of directories, which allows us to determine in detail how storage space is used.

The DU command’s characteristics include the following:

  • Defaults to reporting size in 1K blocks (usually 512-byte or 1024-byte depending on the system).
  • Can scan directories recursively.
  • Will report size in terms of actual disk blocks allocated (not by visible size).
  • Is part of the GNU coreutils (installed by default on most systems).
  • Runs extremely fast on small directory trees and scales up with optimizations.

As cloud storage costs continue to grow, Docker containers cause an exponential increase in size without realizing it, AI models generate a huge number of cached files, and WordPress will continue to create large amounts of uploaded files, mastering the DU command in linux will quickly help identify why there are so many files stored on your storage.

History & Evolution of the DU Command

The first version of the DU command in linux was included in UNIX Version 7 released in 1979

It has been developed by the BSD, System V, and GNU operating systems up to the present time. The DU command in linux that is part of GNU coreutils (version 9.5+) contains additional functionality such as the ability to report the apparent size of files and to count inodes for new filesystems (Btrfs, ZFS, XFS).

DU Command Syntax & Structure

Basic syntax: du [OPTIONS] [PATH...]

Component Description Example
OPTIONS Flags controlling output/behavior -h --max-depth=1
PATH Files/directories to analyze /var/log /home/user
(no PATH) Current directory (.) du -sh *

Output format: [SIZE][UNIT] [PATH]
Example: 2.4G /var/log/apache2

25+ Essential DU Command Options

Linux’s DU command allows for a high level of customization. The most important options are as follows:

Output Format Options

du -h               # Human-readable (K,M,G) 
du -k               # Display in kilobytes only 
du -m               # Display in megabytes only 
du -B M             # Allow for users to specify their own block sizes(M=MB) 
du --apparent-size  # Show size of a file versus the physical disk it is stored on 
du --inodes         # Show the number of files as opposed to the number of bytes

Recursion Control

du -d 1             # Display max depth of 1 (display only the top level) 
du --max-depth=0    # Display only the totals of the entire contents 
du -s               # Display the total only (this will provide the total of everything) 
du -a               # Display all files, but do not display any summaries for the folders

Filtering & Scoping

du -x               # Will display the contents of the same filesystem 
du --exclude="*.log" # Will zip files matching this pattern 
du --exclude-from=file # Will zip any files matching the patterns in the specified file 
du -L               # Will follow the symbolic links 
du --one-file-system # Will not display the contents of any mount points

15 Basic DU Command Examples

Familiarize yourself with these DU commands in Linux:

  1. du -h .Represents human readable sizes of files within a directory (current directory)
  2. du -sh /varRepresents the total size of a directory (/var)
  3. du -sh * | sort -rhLists all files within current directory sorted by size (largest file first)
  4. du -h --max-depth=1 /homeShow sizes of user’s home directories
  5. du -ah /tmp | head -20Lists the largest 20 files in /tmp
  6. du -sh /var/log/*Lists individual sizes of log files (/var/log)
  7. du -ch --max-depth=1 / | Sort the above listing in human-readable order and display a summary (total size of the root filesystem)
  8. sudo du -sh /rootShows user (root) home directory (must be run with super user privileges)
  9. du -h --exclude='*.tmp' /tmpExcludes temporary files
  10. du --apparent-size -h /sparse/filesShows the actual size of sparse files
  11. du --time -h /var/logShows the last modification time of each log file
  12. du --inodes /homeDisplays a count of each file and the total number of files
  13. du -sh /var/lib/docker/* | sort -rh | head -5Lists the 5 largest Docker images
  14. du -h /proc/* 2>/dev/null | sort -hLists all the process folders that are running, and excludes all permissions related errors
  15. du -sh wp-content/uploads/* | sort -rhLists the WordPress uploads that take the most disk space

Advanced DU Command Techniques

Pipeline Power Combinations

# Top 10 largest subdirectories
du -h --max-depth=1 | sort -rh | head -10

# Real-time monitoring
watch -n 5 'du -sh /var/log/* | sort -rh'

# Find files > 100MB recursively
du -aBM | awk '$1 > 100 {print}'

# Export to CSV for Excel analysis
du -h --max-depth=1 | sed 's/\s\+/,/g' > usage.csv

Complex Exclusions

du -h --exclude-from=/root/du-exclude.txt / \
  --exclude='/proc/*' --exclude='/sys/*'

DU vs DF: Complete Comparison

Feature DU Command DF Command
Scope Files & Directories Filesystems
Granularity Recursive tree Mount point totals
Speed Slower (recursive) Instant
Use Case “What’s using space?” “How much free?”
Permissions Needs access to files Root filesystem view

Pro tip: Always run df -h first, then du to investigate.

10 Real-World DU Scenarios

  1. Log file explosion: du -sh /var/log/* | sort -rh | head
  2. Docker cleanup: du -sh /var/lib/docker/overlay2/* | sort -rh
  3. WordPress bloat: du -sh wp-content/uploads/* | sort -rh
  4. Mail server: du -sh /var/mail/* | sort -rh
  5. Database temp: du -sh /var/lib/mysql/tmp/*
  6. NPM cache: du -sh ~/.npm/_cacache/*
  7. Git repos: du -sh .git/* | sort -rh
  8. Container volumes: du -sh /var/lib/docker/volumes/*
  9. APT cache: du -sh /var/cache/apt/archives/*
  10. Security scan: du -ah /tmp | sort -rh | head -50

Troubleshooting DU Command Issues

Problem: Permission denied

sudo du -shx / 2>/dev/null

Problem: Takes forever

du -h --max-depth=1 -x /

Problem: Sizes don’t match df

  • Reserved blocks (5% root)
  • Deleted-but-open files: lsof | grep deleted
  • Sparse files: du --apparent-size

Performance Optimization for DU

  • --max-depth=1 – Limit recursion
  • -x – Stay on filesystem
  • Pipe to head: du ... | head -20
  • Background: nohup du -sh * > usage.txt &
  • Parallel: parallel du -sh ::: dir1 dir2 dir3

20 DU Aliases + 5 Powerful Scripts

Essential Aliases (.bashrc)

alias dus='du -sh * 2>/dev/null | sort -rh'
alias du1='du -h --max-depth=1'
alias du10='du -h --max-depth=1 | sort -rh | head -10'
alias dut='du --time -h'
alias duhome='du -sh ~/* 2>/dev/null | sort -rh'
alias dulog='du -sh /var/log/* 2>/dev/null | sort -rh'
alias duwp='du -sh wp-content/* 2>/dev/null | sort -rh'
alias dudocker='du -sh /var/lib/docker/* 2>/dev/null | sort -rh'
alias dux='du -shx * 2>/dev/null | sort -rh'
alias duall='du -ah . | sort -rh | head -20'

Power Script: Space Hogs Report

#!/bin/bash
echo "=== TOP SPACE HOGS ==="
du -h --max-depth=1 / 2>/dev/null | sort -rh | head -15
echo -e "\n=== LOG FILES ==="
du -sh /var/log/* 2>/dev/null | sort -rh | head -10
echo -e "\n=== HOME DIRS ==="
du -sh /home/* 2>/dev/null | sort -rh

DU with Find, Sort, Watch

# Find largest 10 files >50MB
find / -type f -size +50M -exec du -h {} + 2>/dev/null | sort -rh | head

# Monitor log growth
watch -n 30 'du -sh /var/log/* | sort -rh | head -5'

# Age-based analysis
du --time --max-depth=1 . | sort -k3

Modern DU Alternatives (2026)

Tool Type Best For
ncdu TUI Interactive navigation
dust (du + rust) CLI Speed + tree view
gtop TUI Real-time monitoring
bashtop TUI System overview

Sysadmin Best Practices 2026

  • Always use 2>/dev/null to suppress errors
  • Combine with sort -rh for instant insights
  • Create directory-specific aliases
  • Schedule cron jobs: 0 2 * * * /root/du-report.sh
  • Monitor Docker/Podman regularly
  • Watch WordPress uploads for clients

25 FAQs: DU Command in Linux

1. What does DU command in Linux stand for?
du in linux stands forDisk Usage – estimates file/directory space.

2. How to get human-readable output with DU command in linux?
du -h /path

3. DU in linux shows different sizes than DF. Why?
DF shows filesystem totals, DU shows allocated blocks + reservations.

4. How to show only total size with DU in linux?
du -s /path

5. Sort DU output largest first?
du -sh * | sort -rh

6. Permission denied with DU command?
sudo du or 2>/dev/null

7. Limit recursion depth in DU?
du -d 1 or --max-depth=1

8. Show all files with DU (not just dirs)?
du -a

9. Exclude patterns from DU scan?
du --exclude='*.log'

10. DU across multiple filesystems?
Use -x to stay on same filesystem.

11. Show file modification time with DU?
du --time

12. Count inodes instead of bytes?
du --inodes

13. Fast DU for huge filesystems?
du --max-depth=1 -x

14. DU multiple directories at once?
du dir1 dir2 dir3

15. Custom block size in DU?
du -BM (MB blocks)

16. Include hidden files in DU?
du -a shows everything.

17. Show grand total with subtotals?
du -c

18. Follow symlinks with DU in linux?
du -L

19. Real-time DU monitoring?
watch 'du -sh /var/log/* | sort -rh'

20. DU for Docker containers?
du -sh /var/lib/docker/*

21. WordPress media optimization?
du -sh wp-content/uploads/*

22. Export DU to CSV?
du -h --max-depth=1 | sed 's/\s\+/,/g'

23. Skip permission errors?
du ... 2>/dev/null

24. Background DU scan?
nohup du -sh * > du.txt &

25. Best DU alias for sysadmins?
alias dus='du -sh * 2>/dev/null | sort -rh'

Master the DU command in Linux and never fear “No space left on device” again. Updated January 2026 for latest coreutils and modern Linux distributions.

Stay Connected with My Coding Journey

Don’t let scammers stop your professional growth. Join our community for more tech safety tips!

For more tutorials and guides, check out: CodingJourney.co.in

Leave a Reply

Your email address will not be published. Required fields are marked *