How to Recover Disk Space When Linux Inodes Are 100% Full
When your disk shows space but cannot write files, the inodes are likely full. This guide provides advanced Linux command-line techniques to locate and safely delete obsolete or excessive file system entries.
Direct Diagnostic & Remediation Summary
- Identify Inode Usage: Use
df -i /path/to/mountpointto confirm inode exhaustion. - Locate Large Directories: Run the following command from the suspected mount point to find directories consuming the most inodes:
find /path/to/mountpoint -xdev -type d -print0 | du --files0-dereference --printf '%h %p ' | sort -rh | head -10. - Cleanup Candidates: Target common culprits like mail queues, session files, or old backup indexes using
find /path/to/cleanup -mtime +30 -delete.
Confirm Inode Exhaustion & Initial Triage
Before deleting anything, you must confirm that the issue is inodes (file entries) and not actual disk space. A full inode count means you cannot create new files, even if gigabytes of space remain unused.
Use the df command with the -i flag to check inode usage for all mounted file systems. This gives a precise view of inode utilization versus block utilization.
df -ihExamine the output. If the 'IUse%' column (or similar) is at 100% for your target partition, but the 'Available' blocks are high, inodes are the culprit.
- Check Specific Mount Point: Always run
df -i /mnt/datato isolate which specific mount point needs attention.
Locating the Inode Culprit: The Search Phase
Inodes are consumed by every file and directory entry, regardless of size. Common culprits include session cache files (e.g., Apache/Nginx logs, temporary directories), mail spool folders, or deep directory structures created by buggy scripts.
We need to find the directories consuming the most inodes. The find command combined with du is extremely effective here.
# Navigate to the mount point where inode usage is high (e.g., /var)
cd /var/
# Execute this complex find/du pipeline:
sudo find . -xdev -type d -print0 | du --files0-dereference --printf '%h %p
' | sort -rh | head -15Explanation of the Command:
find . -xdev -type d -print0: Finds all directories recursively starting from '.', ensuring it stays on the same filesystem (-xdev).du --files0-dereference --printf '%h %p ': Calculates disk usage (blocks) for these found directories and prints the count (%h) followed by the path (%p).sort -rh | head -15: Sorts the results numerically in reverse order (largest first) and shows only the top 15 entries.
Targeted Remediation & Safe Deletion
Once Step 2 reveals a directory (e.g., /var/spool/mail or /tmp/session_cache) that is disproportionately large in inode count, you can safely clean it up. NEVER run deletion commands on system directories like /etc without extreme caution.
Focus on temporary, log, or cache areas.
- Old Logs/Cache: Use
find /path/to/logs -type f -mtime +30 -deleteto delete files older than 30 days. - Emptying Directories Safely: If you suspect a directory is full of small, useless entries (like old session IDs), use the following structure after careful review:
sudo find /path/to/directory -mindepth 1 -empty -delete(This only deletes empty directories). - Manual Deletion Confirmation: For suspect directories identified in Step 2, run an
ls -lR /suspect/dirfirst to see what is being counted before deletion. Then, usesudo rm -rf /suspect/dir/*only if you are certain of the contents' disposability.
Verification, Results & Preventative Maintenance
After performing deletions, it is crucial to verify that inodes have been freed and the system is stable. Never assume cleanup worked; always check the metrics again.
- Re-check Inodes: Run
df -i /path/to/mountpointone last time. The 'IUse%' should have dropped significantly from 100%. - Test Write Operation: Attempt to create a small test file in the previously problematic directory:
touch /path/to/test_file_after_cleanup. If this command succeeds without errors, your inode issue is resolved.
Preventative Maintenance Tips:
- Configure log rotation using
logrotatefor critical services like Apache or Nginx to prevent logs from growing unbounded. - Set up automated cleanup jobs (e.g., via cron) to prune temporary directories (
/tmp, application caches) nightly. - Understand that high inode counts are often symptomatic of a runaway process or poorly managed logging infrastructure, not just random junk files.
find and du commands. If symptoms persist, investigate specific application logs or kernel message buffers.Common Pitfalls & Advanced Troubleshooting
If standard remediation does not immediately resolve the symptoms for How to Recover Disk Space When Linux Inodes Are 100% Full, review these advanced diagnostic contingencies on Linux:
- Peripheral & Bus Isolation: Detach non-essential USB accessories and external controllers to isolate IRQ and bus contention.
- Diagnostic Minimal Boot: Restart Linux in Safe / Diagnostic Mode to eliminate third-party daemon conflicts.
- Firmware Integrity: Check that hardware firmware and UEFI/BIOS revisions are updated to the manufacturer baseline.
df -ih
sudo find . -xdev -type d -print0 | du --files0-dereference --printf '%h %p
' | sort -rh | head -15
sudo find /path/to/logs -type f -mtime +30 -delete
touch /path/to/test_file_after_cleanup
Frequently Asked Questions
What is the difference between disk space and inodes?
Disk space refers to the total capacity (measured in bytes) available on the physical drive. Inodes are data structures that store metadata about a file (its name, size, permissions, location). A full inode means you cannot create new files or directories, even if gigabytes of free space remain.
Can I use 'rm -rf /' to fix this?
Absolutely not. This command recursively deletes everything on the root filesystem and will brick your system instantly. Only delete contents within highly restricted, verified subdirectories identified by the diagnostic tools provided.
Does this apply to network shares (NFS/SMB)?
The concept applies, but cleanup procedures must be executed on the server exporting the share, not the client accessing it, as the client only reports what the server allows.
Need help implementing this solution?
Our cybersecurity and infrastructure engineers can audit, harden, or configure your systems directly.
Community Discussion & Confirmations (0)
Technical questions, hardware findings, and verified fix reports.
No reader questions posted yet. Have you tried this solution or experienced an edge case? Post below.