Nextcloud Storage Full After Deleting Files: Diagnose and Reclaim Space Safely
A verified Nextcloud 30, 31, and 32+ sysadmin runbook to trace why df -h stays at 100% after deleting files and safely reclaim Trashbin (files_trashbin), File Versions, appdata_*/preview, WebDAV upload chunks, oc_filecache orphans, and cross-folder duplicates without corrupting the index.
Direct answer
When Nextcloud storage stays full after deleting files, disk space is usually held by the Trashbin (files_trashbin), historical File Versions (files_versions), bloated preview caches under appdata_*/preview, abandoned WebDAV upload chunks, or cross-folder duplicates. Never wipe data/ with rm -rf. Reclaim space safely using occ trashbin:cleanup, occ versions:cleanup, occ preview:cleanup, occ files:cleanup, config.php retention policies, and VFS-safe deduplication.
1. Why Nextcloud storage stays full after deleting files
Every self-hosted Nextcloud administrator hits this incident sooner or later. A server monitoring alert fires at 98% disk usage, users delete 150 GB of old videos and archives in the Nextcloud web interface, desktop clients finish syncing, and yet df -h still reports the exact same 98% full partition. Worse, when an admin panics and runs rm -rf directly inside data/, Nextcloud throws 503 or 404 sync errors, quotas stay wrong, and desktop clients re-upload files or wipe local folders.
Nextcloud is not a flat POSIX filesystem. It is a virtual filesystem (VFS) backed by a relational metadata index (oc_filecache and oc_storages) plus three safety layers designed to protect users from accidental data loss. When you delete or overwrite files, five separate mechanisms continue holding physical blocks on disk or object storage:
- Soft-deletion into
files_trashbin: Deleting a file moves it fromdata/<user>/files/todata/<user>/files_trashbin/files/. By default, Nextcloud keeps deleted items for at least 30 days and allows each user's trashbin to consume up to 50% of available space before background pruning activates. - Historical revisions in
files_versions: Every time a user saves a Photoshop file, SQLite database, presentation, or synced spreadsheet, Nextcloud copies the previous state intodata/<user>/files_versions/. A 200 MB file edited 15 times can quietly occupy 2 to 3 GB of version history even after the active file is trimmed. - Multi-resolution thumbnail explosion in
appdata_<instanceid>/preview: Nextcloud generates multiple cropped and scaled preview images per photo, PDF, and video. Becausepreview_max_xandpreview_max_ydefault to4096pixels, high-megapixel camera libraries routinely build a preview cache weighing 30% to 80% of the original media size and millions of inodes. - Abandoned WebDAV upload chunks and orphaned
oc_filecacherows: Large desktop or mobile uploads are split into chunks underdata/<user>/uploads/. If systemcron.phpis misconfigured (left on AJAX or failing due to a full disk), interrupted multi-gigabyte chunks never expire aftercache_chunk_gc_ttl(86,400 seconds). Meanwhile, removed external storages or deleted accounts can leave orphaned rows inoc_filecache. - Cross-folder and cross-user duplicates: Even when users delete one copy of a heavy video, ZIP archive, or camera roll folder, identical or near-identical copies often remain in shared project directories, second mobile auto-upload folders, or team member accounts.
At the operating-system layer, three additional traps can mask freed space: open deleted file descriptors still pinned by PHP-FPM, Apache, or MariaDB (lsof +L1), copy-on-write snapshots on ZFS or Btrfs keeping old extents alive, and an unrotated multi-gigabyte data/nextcloud.log file. A disciplined recovery always diagnoses before deleting anything.
2. Quantified comparison: 5 hidden causes of full Nextcloud disks
Use the matrix below to match each storage consumer to its exact read-only diagnostic command, its safe Nextcloud occ or VFS cleanup path, the corruption risk if you bypass Nextcloud with rm -rf, and the typical disk space recovered on a 1 TB production server.
| Hidden storage consumer | Disk & SQL diagnostic | Safe occ / VFS cleanup |
Risk if wiped with rm -rf |
Typical space reclaimed |
|---|---|---|---|---|
1. User Trashbin (files_trashbin) |
du -sh data/*/files_trashbin + SQL path LIKE 'files_trashbin/%' |
occ trashbin:cleanup --all-users --verbose or occ trashbin:expire |
Orphaned rows in oc_files_trash & oc_filecache; broken web Trashbin UI errors |
10% to 35% immediately after bulk deletions |
2. File Versions (files_versions) |
du -sh data/*/files_versions + SQL path LIKE 'files_versions/%' |
occ versions:cleanup (or targeted --path) + occ versions:expire |
Broken Versions sidebar, missing restore targets, stale database cache metadata | 5% to 25% on active document and design teams |
3. Preview Cache (appdata_*/preview) |
du -sh data/appdata_*/preview + df -i (inodes) |
occ preview:cleanup (or wipe + mandatory occ files:scan-app-data preview) |
Broken thumbnails in Photos/Memories and stale oc_filecache rows until appdata rescan |
10% to 40% (and 40% to 70% of used inodes) |
4. Abandoned WebDAV chunks & oc_filecache orphans |
du -sh data/*/uploads + SQL LEFT JOIN oc_storages |
Fix cron.php + cache_chunk_gc_ttl; run occ files:cleanup |
Deleting active in-flight chunks corrupts ongoing desktop client transfers | 2% to 15% on unstable WAN links or broken cron |
| 5. Cross-folder & media duplicates | occ duplicates:find-all + occ duplicates:stats --min-size=10M |
Native VFS deletion via Duplicate Finder / Duplicate Finder Pro + final trashbin:cleanup |
fdupes -d breaks oc_filecache, desyncs desktop ETags, and splits Apple Live Photos |
15% to 45% across photos, videos, PDFs, and shared folders |
Notice the compounding effect. Administrators who only empty the trashbin recover space for two weeks before the disk fills again. Combining safe occ maintenance with retention caps in config.php and VFS-safe deduplication permanently lowers baseline storage consumption by 35% to 65% on typical multi-user instances.
3. Step 1: Read-only disk, inode, lsof, and oc_filecache SQL diagnostics
Before running a single cleanup command, take a 60-second read-only inventory at both the Linux filesystem layer and the Nextcloud database layer. This prevents guessing and immediately exposes whether the bottleneck is physical bytes, exhausted inodes, deleted open files, or database bloat.
# 1. Check both disk space (bytes) and inode exhaustion
df -h /var/www/nextcloud/data
df -i /var/www/nextcloud/data
# 2. Measure the top Nextcloud storage buckets (adjust DATA_DIR to your config.php datadirectory)
DATA_DIR="/var/www/nextcloud/data"
du -sh "$DATA_DIR/nextcloud.log"* 2>/dev/null
du -sh "$DATA_DIR"/appdata_*/preview 2>/dev/null
du -sh "$DATA_DIR"/*/files_trashbin 2>/dev/null | sort -hr | head -n 15
du -sh "$DATA_DIR"/*/files_versions 2>/dev/null | sort -hr | head -n 15
du -sh "$DATA_DIR"/*/uploads 2>/dev/null | sort -hr | head -n 15
# 3. Check if deleted files are still pinned open by PHP-FPM, Apache, or MariaDB
sudo lsof +L1 | grep -E "nextcloud|php|apache|nginx|mariadbd|mysqld|postgres" | head -n 25
If your instance uses Primary S3 Object Storage (objectstore in config.php), du -sh on local disk will show almost nothing because user blobs live as urn:oid:<fileid> objects in the bucket. In both local and S3 deployments, querying oc_filecache in read-only SQL gives you the exact breakdown by category and user without scanning millions of files on disk:
-- 1. Storage breakdown by Nextcloud VFS category (works on both MariaDB and PostgreSQL)
SELECT
CASE
WHEN path LIKE 'files_trashbin/%' THEN 'Trashbin (files_trashbin)'
WHEN path LIKE 'files_versions/%' THEN 'Versions (files_versions)'
WHEN path LIKE 'appdata_%/preview/%' THEN 'Previews (appdata_*/preview)'
WHEN path LIKE 'uploads/%' THEN 'Upload chunks (uploads)'
WHEN path LIKE 'files/%' THEN 'Active files (files)'
ELSE 'Other metadata / root'
END AS category,
COUNT(*) AS rows_count,
ROUND(SUM(size) / 1024.0 / 1024.0 / 1024.0, 2) AS total_gb
FROM oc_filecache
WHERE size > 0
GROUP BY 1
ORDER BY total_gb DESC;
-- 2. Top 15 users consuming space in Trashbin + Versions combined
SELECT
s.id AS storage_id,
ROUND(SUM(CASE WHEN fc.path LIKE 'files_trashbin/%' THEN fc.size ELSE 0 END) / 1073741824.0, 2) AS trash_gb,
ROUND(SUM(CASE WHEN fc.path LIKE 'files_versions/%' THEN fc.size ELSE 0 END) / 1073741824.0, 2) AS versions_gb,
ROUND(SUM(CASE WHEN fc.path LIKE 'files/%' THEN fc.size ELSE 0 END) / 1073741824.0, 2) AS active_gb
FROM oc_filecache fc
JOIN oc_storages s ON s.numeric_id = fc.storage
WHERE s.id LIKE 'home::%'
GROUP BY s.id
ORDER BY (trash_gb + versions_gb) DESC
LIMIT 15;
-- 3. Detect orphaned oc_filecache rows whose storage no longer exists in oc_storages
SELECT COUNT(*) AS orphaned_filecache_rows
FROM oc_filecache fc
LEFT JOIN oc_storages s ON s.numeric_id = fc.storage
WHERE s.numeric_id IS NULL;
Keep two caveats in mind when reading oc_filecache totals. First, directory rows aggregate child sizes in Nextcloud, so if you sum all rows without filtering by file mimetype, directories and files will be double-counted; the category query above is ideal for relative ratios, and you can add AND mimetype <> (SELECT id FROM oc_mimetypes WHERE mimetype = 'httpd/unix-directory') for exact leaf-file totals. Second, never run manual DELETE FROM oc_filecache statements during an outage; always execute the official occ maintenance commands below.
4. Step 2: Reclaiming Trashbin and File Versions safely via occ
Once your read-only audit confirms heavy consumption in files_trashbin or files_versions, reclaim space strictly through Nextcloud's occ CLI running as the web-server HTTP user (typically www-data on Debian/Ubuntu, apache on RHEL/Rocky, or via docker exec -u www-data <container> php occ ...). If APCu is enabled for PHP CLI, include --define apc.enable_cli=1.
Understanding occ trashbin:size vs occ trashbin:cleanup vs occ trashbin:expire
Many blog posts confuse these three commands. According to the official Nextcloud Server occ documentation, each command plays a distinct operational role:
occ trashbin:sizeconfigures or shows the target size limit (not current disk usage): Running it without arguments prints the global default (default (50% of available space)). You can cap the global target withocc trashbin:size 10 GBor cap a single heavy account withocc trashbin:size --user alice 5 GB. Changing the global default triggers a cleanup of existing trashbins, though an individual user's trash may temporarily exceed the cap until their next deletion.occ trashbin:cleanuppermanently purges deleted files right now: Pass either one or more user IDs (occ trashbin:cleanup alice bob) or--all-users(never both together). Add--verboseto print the exact bytes reclaimed per user.occ trashbin:expireenforces your custom retention rule: It deletes items older than the upper bound set intrashbin_retention_obligationinsideconfig.php. Critical detail: iftrashbin_retention_obligationis still set to default'auto',occ trashbin:expireexits with an informational notice and deletes nothing because auto-expiration is driven by the background job.
# 1. Inspect current trashbin target size cap (default: 50% of available space)
sudo -E -u www-data php occ trashbin:size
sudo -E -u www-data php occ trashbin:size --user alice
# 2. Optional: enforce a hard global or per-user trashbin target cap
sudo -E -u www-data php occ trashbin:size 10 GB
sudo -E -u www-data php occ trashbin:size --user alice 5 GB
# 3. Immediately empty trashbins for a single heavy user or all users (with freed byte report)
sudo -E -u www-data php occ trashbin:cleanup --verbose alice
sudo -E -u www-data php occ trashbin:cleanup --all-users --verbose
# 4. Expire only items exceeding custom config.php retention (requires non-'auto' setting)
sudo -E -u www-data php occ trashbin:expire
# 5. Clean historical file versions (all users, specific user, or specific folder path)
sudo -E -u www-data php occ versions:cleanup alice --path="/alice/files/Videos"
sudo -E -u www-data php occ versions:cleanup alice
sudo -E -u www-data php occ versions:cleanup
# 6. Or expire only versions older than versions_retention_obligation in config.php
sudo -E -u www-data php occ versions:expire
Before running global occ versions:cleanup on a multi-tenant team server, communicate a short maintenance window or target only the top two heavy paths with --path first. Removing versions does not touch active files, but users will no longer be able to roll back yesterday's edits once version history is purged.
5. Step 3: Cleaning Previews, WebDAV upload chunks, and oc_filecache orphans
When your partition is still above 80% utilization (or df -i shows inode usage above 80%) after clearing Trashbin and Versions, the next three culprits are preview thumbnails, interrupted WebDAV chunked uploads, and orphaned database cache entries.
Clearing and capping appdata_*/preview without breaking Nextcloud Photos or Memories
On modern Nextcloud releases, the cleanest built-in way to reclaim preview storage is sudo -E -u www-data php occ preview:cleanup. It removes all generated preview files cleanly across both local POSIX storage and Primary S3 Object Storage, after which Nextcloud regenerates thumbnails on demand as users browse folders. If you are on an older installation or manually clear data/appdata_<instanceid>/preview/* on local disk, you must immediately run occ files:scan-app-data preview. Unlike user files, Nextcloud has no background cron job that automatically rescans appdata; skipping that scan leaves thousands of stale database rows and broken photo grids in Nextcloud Photos and Memories.
Before letting previews regenerate, lower preview_max_x and preview_max_y from the 4096-pixel default to 2048 (or 1920) in config.php so the cache does not immediately balloon back to its previous size. If you use the community previewgenerator app, tune its target sizes and run occ preview:pre-generate incrementally via cron rather than generating unbounded 4K thumbnails.
Clearing stale WebDAV upload chunks and orphaned oc_filecache rows
One common misconception copied from legacy ownCloud tutorials is attempting to run occ dav:cleanup-chunks. That command belongs to ownCloud and does not exist in Nextcloud Server. In Nextcloud, interrupted WebDAV upload fragments stored under data/<user>/uploads/ are reaped automatically by Nextcloud's background cron job once they exceed cache_chunk_gc_ttl (default 86400 seconds, or 24 hours). When stale upload chunks accumulate to tens of gigabytes, the root cause is almost always that system cron.php stopped running or was left in AJAX mode on a low-traffic instance.
# 1. Clean all generated previews safely (works on local disk AND Primary S3 Object Storage)
sudo -E -u www-data php occ preview:cleanup
# 2. If you manually removed files inside data/appdata_<id>/preview on an older setup, rescan appdata:
sudo -E -u www-data php occ files:scan-app-data preview
# 3. Remove orphaned oc_filecache rows that have no matching record in oc_storages
sudo -E -u www-data php occ files:cleanup
# 4. Verify background jobs use system cron (not AJAX) so WebDAV upload chunks expire automatically
sudo -E -u www-data php occ background:cron
sudo -E -u www-data php occ config:app:get core lastcron
# 5. Only if someone previously ran rm/mv outside Nextcloud, reconcile a targeted user tree:
sudo -E -u www-data php occ files:scan --unscanned --all
# Or targeted single user:
sudo -E -u www-data php occ files:scan alice
If lsof +L1 revealed an active process holding a deleted multi-gigabyte log or temporary file, gracefully reload that daemon (for example sudo systemctl reload php8.3-fpm or sudo systemctl restart apache2) so the Linux kernel immediately releases the unlinked blocks back to df -h. If your server runs on ZFS or Btrfs, remember that freeing 200 GB inside Nextcloud will not show up in zpool list or btrfs filesystem df until older filesystem snapshots referencing those deleted blocks rotate out.
6. Step 4: Reclaiming the last 15% to 45% hidden in duplicate files
Clearing Trashbin, Versions, Previews, and stale upload chunks solves an immediate storage emergency. However, on almost every instance older than 12 months, you will still find 15% to 45% of active storage wasted by redundant copies that users never realize exist: phone auto-uploads re-synced after a device replacement, shared project archives copied into four team folders, HEIC images converted alongside JPEGs, burst shots, and re-saved PDFs or MP4 videos.
Resist the temptation to run fdupes -d, jdupes, or rmlint directly against Nextcloud's data/ directory. As documented in detail in our engineering guide on removing duplicate files in Nextcloud without breaking oc_filecache, deleting files behind Nextcloud's back leaves ghost entries in oc_filecache, corrupts desktop sync ETags, breaks public share tokens, and separates Apple Live Photo .HEIC + .MOV pairs. Instead, audit duplicates read-only with the open-source Nextcloud Duplicate Finder app (eldertek/duplicatefinder, AGPL-3.0 on the Nextcloud App Store) and execute deletions strictly through Nextcloud's VFS:
# 1. Index duplicate files across all users (or scope to one user and folder first)
sudo -E -u www-data php occ duplicates:find-all
sudo -E -u www-data php occ duplicates:find-all --user=alice --path="./Photos"
# 2. Read-only storage waste report: total reclaimable space, per-user totals, top extensions & folders
sudo -E -u www-data php occ duplicates:stats --min-size=10M --output=table
sudo -E -u www-data php occ duplicates:stats --min-size=10M --output=json
# 3. Cross-user read-only audit of the 50 largest duplicate groups (>= 10 MB, excluding received shares by default)
sudo -E -u www-data php occ duplicates:list-all --min-size=10M --limit=50
# 4. Detect entire duplicated directory trees for a specific user
sudo -E -u www-data php occ duplicates:folders --user=alice --min-size=50M
# 5. List a user's duplicate groups sorted from largest waste to smallest
sudo -E -u www-data php occ duplicates:list --user=alice --sort=size-desc --min-size=5M
Notice one critical operational step after cleaning duplicates through Nextcloud's VFS: because safe VFS deletion routes removed duplicates through Nextcloud's standard deletion pipeline (Node::delete()), deleted copies land safely in files_trashbin first so you can review and restore any mistake. Once you verify your cleanup batch, run sudo -E -u www-data php occ trashbin:cleanup --all-users --verbose to commit the freed blocks to disk.
For photo-heavy and mixed-media teams where byte-identical SHA-256 matching misses re-compressed HEIC/RAW bursts, re-muxed MP4/MOV faststart clips, re-saved PDFs, or duplicated ZIP/TAR archives, Duplicate Finder Pro (v0.2.0 for Nextcloud 28 to 35, 19 EUR one-time 100% offline Ed25519 license) extends the open-source engine with 4 dedicated format packs (Documents/PDF SimHash, Modern Photos HEIC/RAW bursts, Video/Audio fingerprinting, Zero-Extraction Archives with Nextcloud tags/comments/shares metadata merge), Storage Trend forecasting, dry-run cleanup policies, and a SHA-256 hash-chained audit log. For specialized media workflows, see our dedicated runbooks on deduplicating HEIC, RAW, and Live Photos without breaking Memories and deduplicating MP4/MOV videos, PDFs, and S3/SMB external storage.
7. Step 5: Production config.php hardening and cron guardrails
Fixing a full disk once is firefighting; locking in bounded retention rules in config/config.php turns storage management into a predictable system. Apply the verified baseline below (adjust retention days to match your internal backup SLA and legal archiving obligations):
<?php
$CONFIG = [
// Keep deleted files at least 7 days (unless quota forces earlier purge),
// and guarantee permanent expiration after 30 days:
'trashbin_retention_obligation' => '7, 30',
// Apply Nextcloud's automatic version aging, but force expiration after 30 days:
'versions_retention_obligation' => 'auto, 30',
// Cap generated preview dimensions (default is 4096 x 4096) and GD memory/size:
'preview_max_x' => 2048,
'preview_max_y' => 2048,
'preview_max_memory' => 256,
'preview_max_filesize_image' => 50,
// Expire abandoned WebDAV upload chunks after 24 hours (default: 86400 seconds):
'cache_chunk_gc_ttl' => 86400,
// Rotate data/nextcloud.log automatically at 100 MB (104857600 bytes):
'log_rotate_size' => 104857600,
];
Production hardening checklist before closing the incident: (1) Verify a real 5-minute systemd timer or crontab entry executes php -f /var/www/nextcloud/cron.php as www-data and confirm occ config:app:get core lastcron updates every 5 minutes; (2) enforce a concrete target cap with occ trashbin:size; (3) configure monitoring alerts at 75% warning and 85% critical on both disk blocks (df -h) and inodes (df -i); (4) schedule a weekly read-only occ duplicates:stats --min-size=10M --output=json check so duplicate sprawl never surprises your team again.
If your team needs ongoing Nextcloud 28 to 35 production maintenance, compatibility sprints, or SLA support, review our Open Source & Nextcloud B2B Support offers or access active licenses and invoices inside the Eclipse Technology Client Portal.
8. Frequently asked questions
Why does Nextcloud still show 100% disk usage immediately after users delete large folders?
Deleting a file in the Nextcloud web UI, mobile app, or desktop client does not unlink the underlying blocks from disk. Nextcloud moves the item into data/<user>/files_trashbin/files/ and keeps historical revisions in files_versions/ plus cached thumbnails inside appdata_<instanceid>/preview/. Until you purge the trashbin with occ trashbin:cleanup --all-users (or let the retention job expire it), df -h will barely change.
Does occ trashbin:size show how many gigabytes are currently used by user trashbins?
No. In Nextcloud 30, 31, and 32+, occ trashbin:size shows or configures the target trashbin size cap (default: 50% of available space), not the current disk footprint in gigabytes. Use occ trashbin:size 10 GB to cap the global target or --user alice 5 GB per user, and run du -sh on data/*/files_trashbin or a read-only SQL query against oc_filecache to measure real bytes consumed.
Why did occ trashbin:expire or occ versions:expire exit without freeing any disk space?
Both occ trashbin:expire and occ versions:expire only run when a custom retention obligation is configured in config/config.php (for example 'auto, 30' or '7, 30'). If your server still uses the default 'auto' setting, Nextcloud skips manual expiration and relies on its background cron job. To force immediate reclamation right now, run occ trashbin:cleanup --all-users --verbose and occ versions:cleanup.
Is it safe to run rm -rf inside data/appdata_*/preview to free disk space?
On modern Nextcloud versions, prefer sudo -E -u www-data php occ preview:cleanup because it clears previews safely on both local disks and Primary S3 Object Storage without leaving stale database references. If you must delete data/appdata_<instanceid>/preview/* directly on an older local-disk instance, you must immediately run sudo -E -u www-data php occ files:scan-app-data preview because no background cron job rescans appdata automatically.
Why did disk usage stay flat after cleaning Nextcloud even though du -sh shows free space?
Three OS-level causes explain a gap between df -h and du -sh: open deleted file descriptors held by PHP-FPM, Apache, or MariaDB (check with lsof +L1), copy-on-write filesystem snapshots on ZFS or Btrfs still pinning deleted extents, or unrotated data/nextcloud.log files when log_rotate_size is disabled. Also verify df -i in case millions of small preview thumbnails exhausted filesystem inodes.
After cleaning Trashbin, Versions, and Previews, why does Nextcloud fill back up quickly?
On mature self-hosted instances, 15% to 45% of active user storage is consumed by duplicate files across folders, repeated mobile camera auto-uploads, shared project copies, HEIC/JPG pairs, and re-saved PDFs or MP4 videos. Run occ duplicates:find-all and occ duplicates:stats with eldertek/duplicatefinder (or Duplicate Finder Pro for perceptual photo/video/PDF/archive packs) to remove duplicates through Nextcloud's VFS, then run occ trashbin:cleanup once verified.
Stop Nextcloud storage bloat permanently with VFS-safe deduplication
After clearing Trashbin, Versions, and Previews with occ, eliminate the hidden 15% to 45% duplicate storage tax without risking oc_filecache corruption. Start with open-source eldertek/duplicatefinder or upgrade to Duplicate Finder Pro v0.2.0 (Nextcloud 28 to 35, 4 Pro format packs for PDF/Office, HEIC/RAW bursts, Video/Audio, and Zero-Extraction Archives, dry-run policies, SHA-256 audit log, 100% offline Ed25519 license for 19 EUR one-time).
Related Nextcloud engineering guides: Remove duplicates safely (oc_filecache) · Deduplicate HEIC/RAW & Memories · Deduplicate Videos, PDFs & S3/SMB · All technical guides