🎁 New User? Get 20% off your first purchase with code NEWUSER20 Register Now β†’
Menu

Categories

Linux Temporary File Management: Cleanup Strategies and Disk Recovery

Linux Temporary File Management: Cleanup Strategies and Disk Recovery

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
Share this article:
Dargslan Editorial Team (Dargslan)
About the Author

Dargslan Editorial Team (Dargslan)

Collective of Software Developers, System Administrators, DevOps Engineers, and IT Authors

Dargslan is an independent technology publishing collective formed by experienced software developers, system administrators, and IT specialists.

The Dargslan editorial team works collaboratively to create practical, hands-on technology books focused on real-world use cases. Each publication is developed, reviewed, and...

Programming Languages Linux Administration Web Development Cybersecurity Networking

Stay Updated

Subscribe to our newsletter for the latest tutorials, tips, and exclusive offers.