reducing_disk_usage_on_ubuntu
This is an old revision of the document!
Table of Contents
Reducing Disk Usage on Ubuntu
This guide provides several techniques to help free up space on your Ubuntu system. These methods can be useful if you are running low on disk space and want to optimize your system's storage.
General Clean-Up Commands
Here are some basic commands to help you get started:
- Remove Orphaned Packages: Removes packages that are no longer required.
sudo apt autoremove
- Remove Unused Dependencies: Manually inspect and remove unnecessary packages.
sudo apt-get remove --purge <package-name>
- Clean Up Old Kernels: Remove old kernels to free up space.
sudo apt-get remove --purge $(dpkg --list | grep -P '^ii\s+linux-image-\d+' | grep -v $(uname -r) | awk '{print $2}')
Manage System Logs
System logs can accumulate over time. Here's how to manage them:
- Clear Systemd Journals: Reduce the size of systemd journal logs.
sudo journalctl --vacuum-time=2weeks
- Remove Old Log Files: Compress and remove older logs in `/var/log/`.
sudo find /var/log -type f -name "*.log" -exec gzip {} \;
sudo find /var/log -type f -name "*.gz" -mtime +30 -exec rm {} \;
Remove Unnecessary Files
- Remove Unused Localization Files: Keep only the locales you need.
sudo apt-get install localepurge sudo localepurge
- Remove Snap Packages: Snap packages can take up a lot of space. Remove them if not needed.
sudo snap remove <package-name> sudo apt purge snapd
- Clear Thumbnail Cache: Remove the thumbnail cache to free up space.
rm -rf ~/.cache/thumbnails/*
- Remove Unnecessary Documentation: Uninstall documentation files for installed packages.
sudo apt-get install --reinstall deborphan sudo deborphan --guess-data | xargs sudo dpkg --purge
- Remove Cached Package Files: Clear out cached `.deb` files.
sudo apt-get clean
Managing Docker Disk Usage
Docker can use a significant amount of disk space. Here’s how to manage it:
- Prune Docker System: Remove unused Docker objects.
docker system prune
- Log Rotation for Docker: Set up a log rotation policy for Docker containers.
{
"log-driver": "json-file",
"log-opts": {
"max-size": "10m",
"max-file": "3"
}
}
Additional Tips
- Check for Large Files: Find large files taking up space.
sudo du -ah / | sort -rh | head -n 20
* **Reduce Image and Video Quality**: Compress images and videos using tools like `ffmpeg` or `imagemagick`. * **Trim the File System**: For SSDs, run the trim command to optimize performance.
sudo fstrim -v /
These methods should help you reclaim significant disk space on your Ubuntu system.
reducing_disk_usage_on_ubuntu.1723680334.txt.gz · Last modified: 2024/10/17 21:42 (external edit)
