सामग्री पर जाएँ
Ubuntu / Linux

One-Command Ubuntu Updates: A Safe Update Script

Save the script as update-system.sh, make it executable and run it. It stops on the first error and tells you if a reboot is needed.

परखा गया Ubuntu 24.04 LTS, 22.04 LTS

Keeping servers patched is the single most effective security habit – and the easiest to skip when it takes four commands. This script runs the whole routine and stops if anything fails.

The script

update-system.sh
#!/usr/bin/env bashn# Update Ubuntu in one command – Inder Kochar (inderkochar.in)nset -euo pipefailnnsudo -v || { echo u0022This script needs sudo rights.u0022 u003eu00262; exit 1; }nnecho u0022==u003e Refreshing package listsu0022nsudo apt updatennecho u0022==u003e Packages that will be upgradedu0022napt list u002du002dupgradable 2u003e/dev/null | tail -n +2nnecho u0022==u003e Upgradingu0022nsudo apt upgrade -ynnecho u0022==u003e Removing packages that are no longer neededu0022nsudo apt autoremove u002du002dpurge -ynnif [ -f /var/run/reboot-required ]; thenn    echo u0022==u003e A reboot is required to finish the update.u0022nelsen    echo u0022==u003e System is up to date.u0022nfi

How to use it

  1. Save it as update-system.sh.
  2. Make it executable: chmod +x update-system.sh
  3. Run it: ./update-system.sh

What it does

  • set -euo pipefail stops the script on the first error instead of carrying on.
  • Lists upgradable packages so you can see what is about to change.
  • Upgrades without prompts, then removes unused dependencies.
  • Checks /var/run/reboot-required and tells you when a kernel or library update needs a restart.

Automate security updates

For unattended servers, Ubuntu’s unattended-upgrades package installs security fixes automatically (sudo dpkg-reconfigure unattended-upgrades). Use this script for the full upgrades you want to watch – or schedule it with the Crontab Generator.

Inder Kochar

लेखक

Inder Kochar

सिस्टम्स और नेटवर्क इंजीनियर – मैं वही समाधान लिखता हूँ जो क्लाइंट्स के साथ इस्तेमाल करता हूँ, असली सिस्टम पर परखे हुए। ऐसी ही किसी समस्या में फँसे हैं?

आगे पढ़ें

सवाल पूछें या अपना समाधान बताएँ

आपका ईमेल प्रकाशित नहीं होगा। टिप्पणियाँ जाँची जाती हैं – कृपया विषय से जुड़ी रखें।