CLYTRIX
All systems operational New York StatusSupportBlog
VPS Management

How to Find and Clean Up Large Files on a Full Linux VPS

How to Find and Clean Up Large Files on a Full Linux VPS

A server’s storage space is a finite resource. In web hosting environments, storage drives accumulate files, databases, log archives, and backups daily. If disk space is not monitored, the server can run out of space entirely, showing a 100% full disk. When this occurs, database engines (such as MySQL/MariaDB) crash, cron jobs fail to run, log files stop writing, and cPanel/Plesk panel operations are blocked.

For systems administrators, resolving a full disk error requires identifying the directories and files consuming the most space without deleting critical operating system files. In this guide, we will explore Linux storage commands, check disk space vs. inode usage, and walk through the SSH commands needed to locate large files, clear log caches, and free up disk space safely.

1. Disk Space (GB) vs. Inode Usage

Linux file systems allocate storage using block space (measured in gigabytes) and inodes. An inode is a data structure that stores metadata about a file or directory. Every file, directory, or link created consumes one inode.

A disk full error can occur due to two different resource limits: block space exhaustion (running out of gigabytes due to large files like videos, database dumps, or logs) or inode exhaustion (running out of index pointers due to millions of tiny files, like session caches or email spools), even if the system shows free disk space. Checking both limits is necessary when troubleshooting storage issues.

2. Step-by-Step Disk Diagnostics via SSH

To troubleshoot disk space issues, log into your server via SSH as the root user. Run these commands to locate large directories, clear system caches, and find large files.

Step 2.1: Check Overall Disk and Inode Status

Verify your server's current block storage and inode usage by running the following commands:

df -h                        # View disk space usage in GB
df -i                        # View inode usage percentage

If either command shows 100% usage, identify where the files are stored using the directories check below.

Step 2.2: Find Large Directories

Use the du (disk usage) command to list the largest directories in a specific path (such as the root folder / or /var/), sorting the output to identify the directories consuming the most space:

du -ah / | sort -rh | head -n 20
# Or check the top-level directories in the root folder
du -h --max-depth=1 / | sort -hr

Common directories that accumulate large files include /var/log/ (system and web server logs), /var/spool/ (mail queues), and /home/ (website files, database files, and backups).

Step 2.3: Find Large Files Globally

Use the find command to search your file system for files exceeding a specific size (e.g., larger than 500MB), listing their paths and sizes:

find / -type f -size +500M -exec ls -lh {} \; | awk '{ print $5, $9 }' | sort -hr

This is a quick way to locate old zip backups, database dumps, or uncompressed log files that can be removed or archived.

Step 2.4: Clean Up Log Files and Caches Safely

System log files (such as /var/log/messages or web server access logs) can grow to several gigabytes if log rotation is not configured correctly. Do not delete active log files using standard rm commands, as running processes may continue writing to the deleted file handle, keeping the disk space locked.

To free up space safely, truncate the log files to 0 bytes by running:

truncate -s 0 /var/log/messages
truncate -s 0 /var/log/nginx/access.log  # On Nginx servers
truncate -s 0 /usr/local/apache/logs/error_log  # On cPanel Apache

You can also clear package manager caches to free up space:

yum clean all                # For RHEL/CentOS/AlmaLinux
apt-get clean                # For Debian/Ubuntu

3. Linux Storage Commands Cheat Sheet

Troubleshooting Action Required SSH Command Usage Purpose
Check Disk space df -h Displays disk capacity and usage in human-readable GB
Check Inode count df -i Displays inode consumption percentages across partitions
Find top 10 large files find / -type f -size +100M | xargs du -h | sort -hr | head -n 10 Locates and lists the largest files on the server
Truncate active logs truncate -s 0 /path/to/log_file Clears log file contents safely without deleting the file handle

Frequently Asked Questions (FAQ)

What are inodes and why can they cause a disk full error?

Inodes store metadata about files. If your website or application creates millions of small files (like session files, email spools, or cache folders), the filesystem can run out of available inodes, showing a disk full error even if you have gigabytes of free block storage space.

How do I configure automatic log cleaning?

Linux uses a tool called **Logrotate** to manage log files. Logrotate splits log files daily or weekly, compresses them, and deletes old archives based on your configuration file settings (located in /etc/logrotate.conf or /etc/logrotate.d/).

Why is my disk space not freed up after deleting a large file?

If a running process (such as a database or web server) is actively writing to a file when you run rm to delete it, the file system removes the directory link but keeps the physical disk space allocated until the process closes the file handle. Restart the service or truncate the file instead to free up the space.

Ready to Put These Guides Into Practice?

Deploy in under 60 seconds. Plans from $0.69/mo.