A simple Bash script that performs a complete system update and cleanup on Debian-based systems.
- Updates package lists (
apt-get update) - Upgrades all installed packages (
apt-get upgrade) - Performs distribution upgrade for better dependency handling (
apt-get dist-upgrade) - Removes unused/orphaned packages (
apt-get autoremove) - Cleans up apt cache (
apt-get autoclean) - Logs all operations with timestamps to
/var/log/system-update.log
- Make the script executable:
chmod +x debian_maintenance_script.sh- Run with sudo (root privileges required):
sudo ./debian_maintenance_script.shAll operations are logged to:
/var/log/system-update.log
Each run is timestamped for easy tracking.
To run this script automatically, add it to your crontab:
sudo crontab -eExample: Run every Sunday at 3 AM:
0 3 * * 0 /path/to/debian_maintenance_script.sh- Debian-based system (Debian, Ubuntu, Linux Mint, etc.)
- Root/sudo privileges
- Bash shell
- This script runs with
-yflag, meaning it will auto-confirm all prompts - Review the log file after execution to check for any issues
- Consider testing on a non-production system first
MIT License - Feel free to use and modify as needed.