The Hidden Cost of Temporary Files
Temporary files accumulate silently on Linux systems. Application crashes, interrupted downloads, and cache buildup can consume gigabytes of disk space without administrators noticing until disk usage alerts fire.
Key Temporary Directories
du -sh /tmp /var/tmp /var/cache /var/log
find /tmp -type f | wc -l
find /var/tmp -type f -mtime +7 | wc -l
Finding Old Temporary Files
# Files older than 7 days in /tmp
find /tmp -type f -mtime +7 -ls
# Large files in cache directories
find /var/cache -type f -size +10M -ls
# Orphaned lock files
find /tmp -name "*.lock" -mtime +1
Safe Cleanup Strategies
# systemd-tmpfiles cleanup
systemd-tmpfiles --clean
# Manual cleanup with safety checks
find /tmp -type f -mtime +30 -not -name "*.sock" -delete
# Clear APT cache
apt-get autoclean
apt-get clean
User Cache Directories
User-level caches can grow surprisingly large:
du -sh ~/.cache ~/.npm ~/.pip/cache
du -sh ~/.local/share/Trash
Automated Cleanup with dargslan-tmpfile-clean
pip install dargslan-tmpfile-clean
dargslan-tmpfile-clean
dargslan-tmpfile-clean --old 30
dargslan-tmpfile-clean --large 50