Combine apt-get update and apt-get upgrade in one command

By | 2012/08/01

On Ubuntu or Debian, it is possible to make a small bash one-liner to fully update the host with one simple command. I’ll show you how!


1. Create a file called ‘update’ in /usr/local/bin:

$ sudo nano /usr/local/bin/update


2. Type the following for the file contents, then save with Control+X.

#!/bin/bash
sudo apt-get update && sudo apt-get upgrade


3. Make it executable:

$ sudo chmod +x /usr/local/bin/update


Now a regular user (with sudo privs) can just type the command ‘update’ to refresh the apt cache and prompt to install any pending updates:

$ update
[sudo] password for user: 
Get:1 http://us.archive.ubuntu.com lucid Release.gpg [189B]
Ign http://us.archive.ubuntu.com/ubuntu/ lucid/main Translation-en_US
Ign http://us.archive.ubuntu.com/ubuntu/ lucid/restricted Translation-en_US
Ign http://us.archive.ubuntu.com/ubuntu/ lucid/universe Translation-en_US
Ign http://us.archive.ubuntu.com/ubuntu/ lucid/multiverse Translation-en_US
Get:2 http://us.archive.ubuntu.com lucid-updates Release.gpg [198B]
Ign http://us.archive.ubuntu.com/ubuntu/ lucid-updates/universe Translation-en_US
Ign http://us.archive.ubuntu.com/ubuntu/ lucid-updates/multiverse Translation-en_US
Get:3 http://us.archive.ubuntu.com lucid Release [57.2kB]
Get:4 http://security.ubuntu.com lucid-updates Release.gpg [198B]
Ign http://security.ubuntu.com/ubuntu/ lucid-updates/main Translation-en_US
Ign http://security.ubuntu.com/ubuntu/ lucid-updates/restricted Translation-en_US
Get:5 http://security.ubuntu.com lucid-security Release.gpg [198B]
Ign http://security.ubuntu.com/ubuntu/ lucid-security/main Translation-en_US
Ign http://security.ubuntu.com/ubuntu/ lucid-security/restricted Translation-en_US
Ign http://security.ubuntu.com/ubuntu/ lucid-security/universe Translation-en_US
Get:6 http://security.ubuntu.com lucid-updates Release [58.3kB]
Get:7 http://us.archive.ubuntu.com lucid-updates Release [58.3kB]
Get:8 http://us.archive.ubuntu.com lucid/main Packages [1,386kB]               
Get:9 http://security.ubuntu.com lucid-security Release [57.3kB]
Get:10 http://security.ubuntu.com lucid-updates/main Packages [627kB]          
Get:11 http://us.archive.ubuntu.com lucid/restricted Packages [6,208B]
Get:12 http://us.archive.ubuntu.com lucid/main Sources [659kB]
Get:13 http://us.archive.ubuntu.com lucid/restricted Sources [3,775B]          
Get:14 http://us.archive.ubuntu.com lucid/universe Packages [5,448kB]          
Get:15 http://us.archive.ubuntu.com lucid/universe Sources [3,165kB]           
Get:16 http://security.ubuntu.com lucid-updates/restricted Packages [4,617B]
Get:17 http://security.ubuntu.com lucid-updates/main Sources [225kB]
Get:18 http://security.ubuntu.com lucid-updates/restricted Sources [2,194B]    
Get:19 http://us.archive.ubuntu.com lucid/multiverse Packages [180kB]          
Get:20 http://us.archive.ubuntu.com lucid/multiverse Sources [119kB]          
Get:21 http://us.archive.ubuntu.com lucid-updates/universe Packages [273kB]    
Get:22 http://security.ubuntu.com lucid-security/main Packages [426kB]        
Get:23 http://us.archive.ubuntu.com lucid-updates/universe Sources [101kB]     
Get:24 http://us.archive.ubuntu.com lucid-updates/multiverse Packages [11.5kB] 
Get:25 http://us.archive.ubuntu.com lucid-updates/multiverse Sources [5,818B]  
Get:26 http://security.ubuntu.com lucid-security/restricted Packages [2,855B]  
Get:27 http://security.ubuntu.com lucid-security/main Sources [127kB]
Get:28 http://security.ubuntu.com lucid-security/restricted Sources [1,259B]
Get:29 http://security.ubuntu.com lucid-security/universe Packages [133kB]
Get:30 http://security.ubuntu.com lucid-security/universe Sources [40.7kB]
Fetched 13.2MB in 5s (2,199kB/s)                         
Reading package lists... Done
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be upgraded:
  libgssapi-krb5-2 libk5crypto3 libkrb5-3 libkrb5support0
4 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 0B/614kB of archives.
After this operation, 0B of additional disk space will be used.
Do you want to continue [Y/n]?
(Reading database ... 40640 files and directories currently installed.)
Preparing to replace libk5crypto3 1.8.1+dfsg-2ubuntu0.10 (using .../libk5crypto3_1.8.1+dfsg-2ubuntu0.11_i386.deb) ...
Unpacking replacement libk5crypto3 ...
Preparing to replace libgssapi-krb5-2 1.8.1+dfsg-2ubuntu0.10 (using .../libgssapi-krb5-2_1.8.1+dfsg-2ubuntu0.11_i386.deb) ...
Unpacking replacement libgssapi-krb5-2 ...
Preparing to replace libkrb5-3 1.8.1+dfsg-2ubuntu0.10 (using .../libkrb5-3_1.8.1+dfsg-2ubuntu0.11_i386.deb) ...
Unpacking replacement libkrb5-3 ...
Preparing to replace libkrb5support0 1.8.1+dfsg-2ubuntu0.10 (using .../libkrb5support0_1.8.1+dfsg-2ubuntu0.11_i386.deb) ...
Unpacking replacement libkrb5support0 ...
Setting up libkrb5support0 (1.8.1+dfsg-2ubuntu0.11) ...

Setting up libk5crypto3 (1.8.1+dfsg-2ubuntu0.11) ...

Setting up libkrb5-3 (1.8.1+dfsg-2ubuntu0.11) ...

Setting up libgssapi-krb5-2 (1.8.1+dfsg-2ubuntu0.11) ...

Processing triggers for libc-bin ...
ldconfig deferred processing now taking place
user@host:~$