Disk Usage and Archives
Introduction
Full disks break deploys and databases. df and du show where space went; tar packages release directories for upload to servers. This chapter covers inspection commands and the archive workflow Java/Node teams use before scp or CI deploy.
Prerequisites
Check Filesystem Space
# Human-readable summary of mounted filesystems
df -h
# Focus on root mount
df -h /Watch Use% near 100%—writes fail, MySQL can crash, logs stop appending.
Inode exhaustion (rare but nasty):
df -iMany tiny files can fill inodes while space looks OK.
Find Large Directories and Files
# Size of each item in current directory
du -sh *
# Home directory total
du -sh ~
# Top-level /var breakdown (may need sudo)
sudo du -sh /var/* 2>/dev/null | sort -hr | headDrill down:
# Largest under /var/log
sudo du -sh /var/log/* 2>/dev/null | sort -hr | headFind huge files:
sudo find / -xdev -type f -size +100M 2>/dev/null | head-xdev stays on same filesystem—avoids crossing mounts.
Common Space Hogs on Servers
| Location | Often contains |
|---|---|
/var/log | syslog, nginx, app logs |
/var/lib | databases (MySQL, Docker) |
~/.gradle/caches | Gradle dependencies |
~/.m2/repository | Maven cache |
/tmp | temporary uploads |
Old releases under /opt | previous JAR versions |
Rotate or compress logs; truncate only when you understand impact.
Mounts and /etc/fstab (Awareness)
Disks attach to directories via mount:
# Currently mounted filesystems
mount | column -t/etc/fstab lists mounts at boot—edit carefully with sudo. Cloud VPS often give one root disk; extra volumes mount at /data.
LVM extends volumes on enterprise servers—concept only here.
tar Archives
Create compressed tarball (common for deploy bundles):
# Create deploy directory sample
mkdir -p ~/release/myapp/{bin,config}
echo "v1" > ~/release/myapp/config/version.txt
# Create .tar.gz: c=create z=gzip f=file v=verbose
tar -czvf myapp-release.tar.gz -C ~/release myapp
# List contents without extracting
tar -tzvf myapp-release.tar.gzExtract:
# Extract to current directory
tar -xzvf myapp-release.tar.gz
# Extract to target path
mkdir -p /opt/myapp
sudo tar -xzvf myapp-release.tar.gz -C /optFlags:
| Flag | Meaning |
|---|---|
c | Create archive |
x | Extract |
z | gzip compression |
v | Verbose list |
f | File name follows |
C | Change directory before add/extract |
zip and unzip
# Install
sudo apt install -y zip unzip
# Create zip
zip -r archive.zip myfolder/
# Extract
unzip archive.ziptar.gz is more common on Linux servers; zip appears when exchanging with Windows.
Deploy Workflow Sketch
On build machine or CI:
# Package built app
tar -czvf myapp-1.2.0.tar.gz -C build/libs myapp-1.2.0.jar config/Upload:
scp myapp-1.2.0.tar.gz deploy@203.0.113.10:/opt/myapp/On server:
cd /opt/myapp
tar -xzvf myapp-1.2.0.tar.gz
sudo systemctl restart myappCI/CD pipelines automate the same steps with SSH or agents.
Clean Up Safely
# Remove old release archives after verify
rm ~/myapp-release.tar.gz
# Clear package cache (Ubuntu)
sudo apt clean
# Old logs — rotate with logrotate instead of blind rm
sudo journalctl --vacuum-time=7dWarning
rm -rf on wrong path deletes production data. Use du and ls to confirm targets. Keep backups before mass delete.
Mini Example: Pre-Deploy Disk Check
# Script-friendly checks
df -h /
du -sh /opt/myapp
du -sh /var/logIf / is above 85% used, clean before uploading a large JAR.
FAQ
df vs du?
df reports filesystem blocks; du sums file sizes—can differ slightly due to metadata and open deleted files.
Delete file but space not freed?
Process still holds file open—restart the service or find PID with lsof (advanced).
tar without z?
.tar only (no gzip)—faster create, larger size. .tar.gz standard for releases.
Exclude files from tar?
tar --exclude='*.log' -czvf ...