Debian virtual machine cache cleanup
Sometimes, our virtual machines, such as Ubuntu and Debian,are installed on the E drive. Simply cleaning up the cache won’t remove it. Here’s a great method to successfully clean up and release the cache.
I. First, check which directory is taking up space
Execute:
df -h
Check which directory is full: /, /home, or /mnt/e.
Then check the main directories:
sudo du -xh / --max-depth=1 | sort -h
The directories that usually take up space are:
-
/var -
/home -
/usr -
/opt -
/tmp
II. APT cache cleanup (usually releases 1~5GB)
sudo apt clean
sudo apt autoclean
sudo apt autoremove -y
Notes:
apt clean: Deletes all downloaded deb package cachesapt autoclean: Deletes expired packagesapt autoremove: Deletes unused dependencies
Cache location:
/var/cache/apt/archives/
III. Clean up journal logs
Check size:
sudo du -sh /var/log/journal
Limit to 200MB:
sudo journalctl --vacuum-size=200M
Or only keep 7 days:
sudo journalctl --vacuum-time=7d
IV. Clean up /var/log old logs
sudo du -sh /var/log/*
If you see some huge files:
sudo truncate -s 0 /var/log/syslog
sudo truncate -s 0 /var/log/kern.log
sudo truncate -s 0 /var/log/auth.log
Or:
sudo rm -f /var/log/*.gz
sudo rm -f /var/log/*.[0-9]
V. pip / conda / python cache
pip cache:
pip cache purge
Or manually:
rm -rf ~/.cache/pip
conda (if installed):
conda clean --all -y
VI. CUDA / Compilation cache
NVCC / torch cache:
rm -rf ~/.nv
rm -rf ~/.cache/torch
rm -rf ~/.cache/nv
rm -rf ~/.cache
CMake / build intermediate files (very large):
For example, you have:
~/GOSK/build
~/xxx/build
Directly:
rm -rf build/
Or:
find ~ -name build -type d -exec rm -rf {} +
VII. Clean up Docker (if installed)
docker system df
docker system prune -a
This will delete all unused images
VIII. Find 10GB+ files (recommended)
sudo find / -type f -size +10G 2>/dev/null
Or:
sudo du -ah / | sort -rh | head -n 50
IX. If you use WSL
If your Debian is WSL and placed on E disk:
Even if you delete the file, the virtual disk file .vhdx will not automatically shrink!
You need to do:
Turn off WSL
In Windows PowerShell (administrator):
wsl --shutdown
Compress virtual disk
Open:
Disk Management → Operation → Attach VHD Find your Debian’s
.vhdx
Then:
Right-click → Compress Volume
Or use:
diskpart
select vdisk file="E:\xxx\ext4.vhdx"
attach vdisk readonly
compact vdisk
detach vdisk
exit
Otherwise, your disk will still look full