Skip to main content

On This Page

Mastering Linux Storage and Disk Space

2 min read
Share

These articles are AI-generated summaries. Please check the original sources for full details.

Mastering Linux Storage: Find Large Files and Free Up Disk Space Fast

The “Disk Full” error on a Linux server can be a significant headache, whether you’re managing a production box or a personal homelab, with the root partition often being the culprit. Running out of space can lead to system crashes and downtime, emphasizing the need for efficient disk management.

Why This Matters

In ideal scenarios, disk space management is straightforward, with ample storage and minimal usage. However, in technical reality, disk space can quickly become a limiting factor, especially in environments with high data turnover or limited storage capacity. For instance, a single large log file or an unused ISO can occupy significant space, leading to a failure scale that affects system performance and potentially incurs significant recovery costs.

Key Insights

  • df -h command provides a human-readable overview of disk usage, highlighting the need for action when the root partition exceeds 95% capacity.
  • du -sh * | sort -h helps identify large folders, while sudo find / -type f -size +100M locates massive files.
  • Tools like ncdu offer a modern, interactive UI for browsing and cleaning up the filesystem.

Working Example

# Check overall disk usage
df -h

# Summarize the current directory's disk usage
du -sh .

# List and sort all folders in the current directory by size
du -sh * | sort -h

# Root partition breakdown
sudo du -xh --max-depth=1 / 2>/dev/null | sort -hr

# Find the Top 20 largest files on the system
sudo find / -type f -printf "%s %p\n" | sort -rn | head -n 20 | awk '{print $1/1024/1024 "MB", $2}'

# Find files larger than 100MB
sudo find / -type f -size +100M -exec ls -lh {} +

# Install and run ncdu for a visual interface
sudo apt install ncdu
ncdu /

Practical Applications

  • Use Case: Companies like Debian and Ubuntu use df and du commands for disk management, ensuring their systems remain operational by regularly checking for and addressing disk space issues.
  • Pitfall: Failing to regularly clean up temporary files and logs can lead to unexpected disk full errors, causing system downtime and potential data loss.

References:


Continue reading

Next article

OpenCode: AI Coding Agent with Multi-Model Support and Native UI

Related Content