UnderHost
Knowledgebase Docs

Zero-Size File Errors: Diagnose and Fix Empty Files

Debug zero-size files on VPS. Identify causes: disk full, partial uploads, crashes. Find and fix empty files. Prevent future occurrences.

On this page

Zero-size files (0 bytes) indicate incomplete writes, interrupted uploads, disk full conditions, or application crashes. They typically cause "permission denied" or "file not found" errors. Finding and fixing zero-size files prevents application failures and data loss.

What Are Zero-Size Files

  • Files with 0 bytes (empty)
  • Appear in directory listings
  • Cause errors when application tries to read them
  • Often indicate incomplete operations

Root Causes

CauseSymptomFix
Disk fullWrite stops mid-fileFree disk space
Interrupted uploadNetwork cut during FTPRe-upload file
App crashProcess killed before write completeRestart app, check logs
PermissionsCan't write to directoryFix permissions (chmod 755)
Out of inodesToo many files (rare)Delete old files

Find Zero-Size Files

# Find all zero-size files in /var/www
find /var/www -size 0 -type f

# Show with details
find /var/www -size 0 -type f -exec ls -la {} \;

# Find in specific directory only
find /var/www/uploads -size 0 -type f

# Count zero-size files
find /var/www -size 0 -type f | wc -l

Diagnose the Problem

Check disk space:**

df -h         # Is disk full?
du -sh /*     # Which directories use space?

# If disk is full:
# - Remove old backups
# - Clear log files
# - Delete tmp files

Check application logs:**

# PHP errors
tail -100 /var/log/php.log

# Nginx/Apache errors
tail -100 /var/log/nginx/error.log

# Application crash logs
tail -100 /var/log/syslog | grep -i error

Check file ownership/permissions:**

ls -la zero-size-file.txt
# Example: -rw-r--r-- 0 www-data www-data 0 Jun 6 12:00

Fix Zero-Size Files

For temporary/cache files (safe to delete):**

# Find and delete zero-size files
find /var/www -size 0 -type f -delete

# Or with confirmation
find /var/www -size 0 -type f -exec rm -i {} \;

For important files (restore from backup):**

# Check if backup exists
ls -la /backups/

# Restore from backup
cp /backups/important-file.txt /var/www/important-file.txt

# Or restore from Git
git checkout important-file.txt

Prevent Future Issues

Monitor disk space:**

alert_threshold=85
current_usage=$(df /var/www | awk 'NR==2 {print $5}' | sed 's/%//')

if [ $current_usage -gt $alert_threshold ]; then
    echo "Disk usage critical!" | mail -s "Alert" admin@example.com
fi

Handle incomplete uploads:**

# PHP: verify file after upload
if ($_FILES['file'],['error'] === UPLOAD_ERR_OK && $_FILES['file'],['size'] > 0) {
    move_uploaded_file($_FILES['file'],['tmp_name'], $destination);
} else {
    // Don't save zero-size file
    error_log("Upload failed or incomplete");
}

Use atomic file writes:**

# Write to temp file first, then rename (atomic)
$temp_file = '/tmp/data-' . getmypid();
file_put_contents($temp_file, $data);
rename($temp_file, '/var/www/data.txt');  // Atomic

Recover Lost Data

  • Check file versioning (Git): git log -p filename
  • Restore from backup: rsync -av backup/ target/
  • Use undelete tools (if recently deleted): testdisk /dev/sda

Monitor for Recurrence

# Cron job to check daily
#!/bin/bash
zero_files=$(find /var/www -size 0 -type f)

if [ -n "$zero_files" ]; then
    echo "$zero_files" | mail -s "Zero-size files detected" admin@example.com
fi

# Add to crontab:
# 0 2 * * * /usr/local/bin/check-zero-files.sh
Zero-size files indicate system problems—always investigate root cause

Don't just delete them. Find out why they appeared (disk full? app crash?). Fix the root cause to prevent recurrence.

Related: File management | Disk troubleshooting | Filesystem errors | Log analysis

Was this article helpful?

Still troubleshooting?

Use UnderHost tools for quick checks, or open a support ticket when the issue needs account or server access.

Back to Troubleshooting