How to Find and Clean Large Files (>100MB) in Linux /home Directory


4 views

html

When performing system maintenance on CentOS 6.x servers, administrators often need to locate and clean large files in the /home directory. The default find command may present some unexpected behaviors on older Linux distributions.

Here's the most robust command combination I've used for years:

find /home -type f -size +100M -exec ls -lh {} \;

Breakdown of this command:

  • /home: The target directory
  • -type f: Only search for files (not directories)
  • -size +100M: Files larger than 100MB
  • -exec ls -lh {}: Display human-readable file sizes

For more detailed output, consider these variations:

# Sort by file size (descending)
find /home -type f -size +100M -exec du -h {} + | sort -rh

# Include file modification time
find /home -type f -size +100M -printf "%TY-%Tm-%Td %TT %p %s\n" | sort -nk7

When running as non-root user, you might encounter permission denied errors. Either:

sudo find /home -type f -size +100M 2>/dev/null

Or to exclude permission errors while keeping other warnings:

find /home -type f -size +100M 2>&1 | grep -v "Permission denied"

To automatically delete files older than 180 days that are larger than 100MB:

find /home -type f -size +100M -mtime +180 -exec rm -v {} \;

Always verify files before deletion by first running without -exec rm.

For very large filesystems, these optimizations help:

# Limit filesystem traversal
find /home -xdev -type f -size +100M

# Use parallel processing (GNU parallel required)
find /home -type f -size +100M -print0 | parallel -0 du -h

When managing CentOS 6.x servers, disk space maintenance is crucial. Here's the most efficient way to find files larger than 100MB in the /home directory:

find /home -type f -size +100M -exec ls -lh {} + | awk '{ print $9 ": " $5 }'

This compound command combines several powerful Unix tools:

  • find /home - Searches recursively starting from /home
  • -type f - Only looks for regular files (not directories)
  • -size +100M - Filters files larger than 100MB
  • -exec ls -lh {} - Displays human-readable file sizes

For more detailed analysis, try these variations:

# Sort by size (descending order):
find /home -type f -size +100M -exec du -h {} + | sort -rh

# Including hidden files and showing permissions:
find /home -type f -size +100M -ls | awk '{print $3,$7,$11}'

# Export results to a file for later review:
find /home -type f -size +100M -exec ls -lh {} + > large_files_report.txt

The older GNU findutils version (4.4.2) on CentOS 6.x may require adjustments:

# If -size +100M fails, try blocks (1 block = 512 bytes):
find /home -type f -size +200000 -print

Before deleting files, consider these precautions:

# Create deletion preview:
find /home -type f -size +100M -printf "Would remove: %p (%s bytes)\n"

# Actual deletion (use with caution):
find /home -type f -size +100M -exec rm -i {} +