H
10Corp Premium Hosting

The du (Disk Usage) Command

Last Updated: 2025-01-01 2 min read

Overview

The du (disk usage) command estimates and displays the disk space used by files and directories. It’s an essential tool for identifying what’s consuming storage on your hosting account.

Basic Syntax

du [options] [path]

If no path is specified, du reports on the current directory.

Common Usage Examples

Check the Size of a Specific Directory

du -sh /home/username/public_html
# Output: 1.2G   /home/username/public_html
  • -s — Summary (total size only, don’t list subdirectories)
  • -h — Human-readable sizes (K, M, G)

List Subdirectory Sizes

du -h --max-depth=1 /home/username/public_html

This shows the size of each immediate subdirectory — extremely useful for pinpointing where space is being used:

250M    /home/username/public_html/wp-content
5.0M    /home/username/public_html/wp-admin
12M     /home/username/public_html/wp-includes
1.2G    /home/username/public_html

Find the Largest Directories

Combine du with sort to rank directories by size:

du -h --max-depth=1 /home/username | sort -rh | head -20
  • sort -rh — Reverse sort by human-readable numbers (largest first)
  • head -20 — Show only the top 20 results

Check Size of All Files in a Directory

du -ah /home/username/public_html | sort -rh | head -20

The -a flag includes individual files, not just directories.

Useful Flags Reference

FlagDescription
-hHuman-readable output (KB, MB, GB)
-sDisplay only the total for each argument
-aInclude individual files, not just directories
--max-depth=NLimit directory depth to N levels
-cProduce a grand total at the end
--exclude=PATTERNSkip files matching the pattern
-kDisplay sizes in kilobytes
-mDisplay sizes in megabytes

Practical Examples for Hosting

Check your entire home directory usage

du -sh ~

Find large log files eating up space

du -ah /home/username/logs | sort -rh | head -10

Exclude certain directories from the count

du -sh --exclude='*.log' /home/username/public_html

Show total size of multiple directories

du -shc /home/username/public_html /home/username/mail

Tips

  • Run du from your home directory with --max-depth=1 as a first step whenever you need to investigate disk usage.
  • Pair du with find to locate specific large files (see the related article on the find command).
  • If your hosting plan is running low on space, check for old backups, large log files, and unused media uploads first.
Tags: ssh linux disk-usage du

Still need help?

Our support team is available 24/7 to assist you.