reducing_disk_usage_on_ubuntu
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| reducing_disk_usage_on_ubuntu [2024/08/14 23:58] – created oso | reducing_disk_usage_on_ubuntu [2024/12/04 04:14] (current) – [Additional Tips] oso | ||
|---|---|---|---|
| Line 8: | Line 8: | ||
| * **Remove Orphaned Packages**: Removes packages that are no longer required. | * **Remove Orphaned Packages**: Removes packages that are no longer required. | ||
| - | | + | < |
| - | sudo apt autoremove | + | sudo apt autoremove |
| - | </ | + | </ |
| * **Remove Unused Dependencies**: | * **Remove Unused Dependencies**: | ||
| - | | + | < |
| - | sudo apt-get remove --purge < | + | sudo apt-get remove --purge < |
| - | </ | + | </ |
| * **Clean Up Old Kernels**: Remove old kernels to free up space. | * **Clean Up Old Kernels**: Remove old kernels to free up space. | ||
| - | | + | < |
| - | sudo apt-get remove --purge $(dpkg --list | grep -P ' | + | sudo apt-get remove --purge $(dpkg --list | grep -P ' |
| - | </ | + | </ |
| ===== Manage System Logs ===== | ===== Manage System Logs ===== | ||
| Line 27: | Line 27: | ||
| * **Clear Systemd Journals**: Reduce the size of systemd journal logs. | * **Clear Systemd Journals**: Reduce the size of systemd journal logs. | ||
| - | | + | < |
| - | sudo journalctl --vacuum-time=2weeks | + | sudo journalctl --vacuum-time=2weeks |
| - | </ | + | </ |
| * **Remove Old Log Files**: Compress and remove older logs in `/ | * **Remove Old Log Files**: Compress and remove older logs in `/ | ||
| - | | + | < |
| - | sudo find /var/log -type f -name " | + | sudo find /var/log -type f -name " |
| - | sudo find /var/log -type f -name " | + | sudo find /var/log -type f -name " |
| - | </ | + | </ |
| ===== Remove Unnecessary Files ===== | ===== Remove Unnecessary Files ===== | ||
| * **Remove Unused Localization Files**: Keep only the locales you need. | * **Remove Unused Localization Files**: Keep only the locales you need. | ||
| - | | + | < |
| - | sudo apt-get install localepurge | + | sudo apt-get install localepurge |
| - | sudo localepurge | + | sudo localepurge |
| - | </ | + | </ |
| * **Remove Snap Packages**: Snap packages can take up a lot of space. Remove them if not needed. | * **Remove Snap Packages**: Snap packages can take up a lot of space. Remove them if not needed. | ||
| - | | + | < |
| - | sudo snap remove < | + | sudo snap remove < |
| - | sudo apt purge snapd | + | sudo apt purge snapd |
| - | </ | + | </ |
| * **Clear Thumbnail Cache**: Remove the thumbnail cache to free up space. | * **Clear Thumbnail Cache**: Remove the thumbnail cache to free up space. | ||
| - | | + | < |
| - | rm -rf ~/ | + | rm -rf ~/ |
| - | </ | + | </ |
| * **Remove Unnecessary Documentation**: | * **Remove Unnecessary Documentation**: | ||
| - | | + | < |
| - | sudo apt-get install --reinstall deborphan | + | sudo apt-get install --reinstall deborphan |
| - | sudo deborphan --guess-data | xargs sudo dpkg --purge | + | sudo deborphan --guess-data | xargs sudo dpkg --purge |
| - | </ | + | </ |
| * **Remove Cached Package Files**: Clear out cached `.deb` files. | * **Remove Cached Package Files**: Clear out cached `.deb` files. | ||
| - | | + | < |
| - | sudo apt-get clean | + | sudo apt-get clean |
| - | </ | + | </ |
| ===== Managing Docker Disk Usage ===== | ===== Managing Docker Disk Usage ===== | ||
| Line 72: | Line 72: | ||
| * **Prune Docker System**: Remove unused Docker objects. | * **Prune Docker System**: Remove unused Docker objects. | ||
| - | | + | < |
| - | docker system prune | + | docker system prune |
| - | </ | + | </ |
| * **Log Rotation for Docker**: Set up a log rotation policy for Docker containers. | * **Log Rotation for Docker**: Set up a log rotation policy for Docker containers. | ||
| - | | + | < |
| - | { | + | { |
| - | " | + | " |
| - | " | + | " |
| - | " | + | " |
| - | " | + | " |
| - | } | + | } |
| - | } | + | } |
| - | </ | + | </ |
| ===== Additional Tips ===== | ===== Additional Tips ===== | ||
| * **Check for Large Files**: Find large files taking up space. | * **Check for Large Files**: Find large files taking up space. | ||
| - | | + | < |
| - | sudo du -ah / | sort -rh | head -n 20 | + | sudo du -ah / | sort -rh | head -n 20 |
| - | </ | + | </ |
| | | ||
| - | * **Reduce Image and Video Quality**: Compress images and videos using tools like `ffmpeg` or `imagemagick`. | + | **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. | + | **Trim the File System**: For SSDs, run the trim command to optimize performance. |
| - | < | + | < |
| - | sudo fstrim -v / | + | sudo fstrim -v / |
| - | </ | + | </ |
| These methods should help you reclaim significant disk space on your Ubuntu system. | These methods should help you reclaim significant disk space on your Ubuntu system. | ||
| + | |||
| + | ===== cronjob ===== | ||
| + | |||
| + | This cron job performs routine maintenance tasks to free up disk space and optimize the system on a low-storage VPS. It includes: | ||
| + | |||
| + | * Journal cleanup: Removes older system logs using journalctl --vacuum-time=7d. | ||
| + | * Docker cleanup: Removes unused Docker objects (containers, | ||
| + | * APT cleanup: Frees space by removing unnecessary packages and cleaning up cached package files using apt autoremove -y and apt clean. | ||
| + | * Kernel cleanup: Removes unused old Linux kernels to free significant space. | ||
| + | * Log cleanup: Deletes compressed logs older than 7 days in /var/log. | ||
| + | * Temporary files cleanup: Deletes unused temporary files older than 24 hours from /tmp and /var/tmp. | ||
| + | * Snap cleanup: Removes old and unused versions of Snap packages. | ||
| + | |||
| + | This script is executed every Friday at 2:00 PM (server time) to keep the VPS lean and functioning efficiently. | ||
| + | <code bash> | ||
| + | 0 14 * * 5 journalctl --vacuum-time=7d && docker system prune -af --volumes && apt autoremove -y && apt clean && dpkg --list | grep linux-image | grep -v $(uname -r) | awk ' | ||
| + | </ | ||
reducing_disk_usage_on_ubuntu.1723679909.txt.gz · Last modified: 2024/10/17 21:42 (external edit)
