All posts

How to find what's eating disk space on a cPanel server

A disk alert on a shared cPanel server is rarely one big mystery file. It's usually a handful of ordinary things that grew unnoticed: a backup tarball someone made by hand, an error_log that's been collecting warnings for three years, a mailbox nobody reads, a database table that never gets pruned.

The worst thing to do is start deleting. The second worst is running du -sh /* and waiting. Here's a methodical way to narrow it down. Everything in steps 1–7 is read-only. Run the commands as root.

1. Confirm what's actually full

df -h
df -i

df -h tells you which filesystem is full. On many cPanel servers /home, /var and /backup are separate mounts, and knowing which one is full saves you from searching the wrong tree.

df -i shows inodes. If IUse% is at or near 100% while space looks fine, you're not looking for big files at all. You're looking for millions of small ones: PHP session files, cache directories, or a mail folder full of bounces. Skip to step 6.

2. Find the biggest accounts

du -xh --max-depth=1 /home 2>/dev/null | sort -rh | head -15

-x keeps du on one filesystem, so it won't wander into other mounts. The output ranks home directories by size. Once you have the worst account, drill in the same way:

du -xh --max-depth=1 /home/USERNAME 2>/dev/null | sort -rh | head -15

Repeat one level deeper until the culprit is obvious. Common findings inside an account:

  • public_html/ with a full copy of the site in old/, backup/ or site-2019/
  • mail/ with years of unread mail or a catch-all address collecting spam
  • logs/, where cPanel archives the account's web logs if archiving is enabled
  • .trash/ from File Manager deletions that were never emptied
  • softaculous_backups/ or similar backup folders from app installers

3. List the largest individual files

find /home -xdev -type f -size +500M -printf '%s\t%p\n' 2>/dev/null \
  | sort -rn | head -20 | numfmt --to=iec --field=1

This prints the 20 largest files over 500 MB, largest first, with human-readable sizes. Lower the threshold to +100M on smaller servers.

You'll typically see .tar.gz and .zip archives, .sql dumps, and occasionally video files someone uploaded to a site. MySQL data files don't show up here, because they live under /var/lib/mysql, not /home.

Oversized logs deserve their own search, since they're the most common surprise:

find /home -xdev -type f -name error_log -size +100M -printf '%s\t%p\n' 2>/dev/null \
  | sort -rn | numfmt --to=iec --field=1

A multi-gigabyte error_log usually means a site is throwing the same PHP warning on every request. Deleting the file fixes the disk, not the problem. Look at the last few lines (tail -n 20) and tell the site owner.

4. Check the databases

du -sh /var/lib/mysql/* 2>/dev/null | sort -rh | head -15

On disk, that's the quickest view. To confirm from MySQL's side, and to see data versus index size:

mysql -e "SELECT table_schema AS db,
  ROUND(SUM(data_length + index_length)/1024/1024) AS mb
  FROM information_schema.tables
  GROUP BY table_schema ORDER BY mb DESC LIMIT 15;"

cPanel database names start with the account username (username_dbname), so it's easy to map the output back to an account. Then look for the biggest tables in the worst database:

mysql -e "SELECT table_name,
  ROUND((data_length + index_length)/1024/1024) AS mb
  FROM information_schema.tables
  WHERE table_schema = 'username_dbname'
  ORDER BY mb DESC LIMIT 10;"

In WordPress, the usual suspects are session, log and analytics tables written by plugins, and a bloated wp_options full of expired transients.

Note that information_schema sizes are estimates for InnoDB, and the on-disk .ibd file can be larger than the live data after heavy deletes.

5. Look outside /home

If / or /var is the full filesystem, check these:

du -sh /backup 2>/dev/null
du -sh /var/log /usr/local/cpanel/logs /etc/apache2/logs/domlogs 2>/dev/null
journalctl --disk-usage
du -sh /var/cache/dnf /var/cache/yum 2>/dev/null
  • /backup is the default destination for WHM backups. If it's on the same disk as everything else, retention is often the whole answer. Check WHM » Backup » Backup Configuration for how many daily, weekly and monthly copies you're keeping.
  • /usr/local/cpanel/logs and /etc/apache2/logs/domlogs hold cPanel's own logs and the live per-domain Apache logs.
  • journalctl --disk-usage matters if journald storage is persistent and has no size cap.

6. Running out of inodes instead of space

If df -i was the problem, count files instead of bytes. This lists the directories directly under an account by number of files:

for d in /home/USERNAME/*/ /home/USERNAME/.[!.]*/; do
  printf '%s\t%s\n' "$(find "$d" -xdev -type f 2>/dev/null | wc -l)" "$d"
done | sort -rn | head

Session directories, cache folders from page-cache plugins, and mail/ folders (especially new/ and cur/ under a catch-all) are the usual causes.

7. When df and du disagree

Sometimes df says the disk is full, but nothing you du adds up to it. The usual cause is a file that was deleted while a process still has it open. The directory entry is gone, but the space isn't freed until the process closes the file.

lsof +L1

This lists open files with a link count of zero, meaning deleted but still held. You'll often see a log file that was removed by hand while Apache, PHP-FPM or MySQL was still writing to it. The space comes back when that service restarts or reopens its logs.

8. Cleaning up safely

Everything above only reads. When you start removing things:

  • Talk to the account owner first about anything inside their home directory. That "old" folder may be the only copy of something.
  • Move before you delete. If you're unsure, move the file to a holding directory on a filesystem with space, and delete it a week later if nobody asks.
  • Don't delete MySQL files from /var/lib/mysql by hand. Drop tables or databases through MySQL, or through cPanel if it's the account's database.
  • Fix the cause. A 20 GB error_log will come back. Retention settings that fill /backup will fill it again.

Doing this across many servers

The commands above work fine for one incident on one server. Across a fleet, or as a monthly check, it's worth having the same scans in one place.

Server Commander, our plugin for cPanel & WHM, includes read-only versions of several steps in this guide, inside WHM:

  • Large Files Finder: scans a directory (default /home) for files over a size you choose, with the option to exclude extensions you expect to be large, like .ibd.
  • Database Storage Auditor: database sizes and table overhead from information_schema, grouped by cPanel account.
  • Server Log Auditor: system logs, per-user error_log files and web server logs, sorted by size.
  • Unoptimized Image Bloat Finder: the 100 largest JPG, PNG and WebP files across every public_html.

None of them delete anything. They report, and you decide. Server Commander is $19.99/month per server, or part of the Server+ Suite.

Whether you use a tool or the terminal, the principle is the same: measure first, then clean up with the account owner in the loop.