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.

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 lucid Release.gpg [189B]
Ign lucid/main Translation-en_US
Ign lucid/restricted Translation-en_US
Ign lucid/universe Translation-en_US
Ign lucid/multiverse Translation-en_US
Get:2 lucid-updates Release.gpg [198B]
Ign lucid-updates/universe Translation-en_US
Ign lucid-updates/multiverse Translation-en_US
Get:3 lucid Release [57.2kB]
Get:4 lucid-updates Release.gpg [198B]
Ign lucid-updates/main Translation-en_US
Ign lucid-updates/restricted Translation-en_US
Get:5 lucid-security Release.gpg [198B]
Ign lucid-security/main Translation-en_US
Ign lucid-security/restricted Translation-en_US
Ign lucid-security/universe Translation-en_US
Get:6 lucid-updates Release [58.3kB]
Get:7 lucid-updates Release [58.3kB]
Get:8 lucid/main Packages [1,386kB]               
Get:9 lucid-security Release [57.3kB]
Get:10 lucid-updates/main Packages [627kB]          
Get:11 lucid/restricted Packages [6,208B]
Get:12 lucid/main Sources [659kB]
Get:13 lucid/restricted Sources [3,775B]          
Get:14 lucid/universe Packages [5,448kB]          
Get:15 lucid/universe Sources [3,165kB]           
Get:16 lucid-updates/restricted Packages [4,617B]
Get:17 lucid-updates/main Sources [225kB]
Get:18 lucid-updates/restricted Sources [2,194B]    
Get:19 lucid/multiverse Packages [180kB]          
Get:20 lucid/multiverse Sources [119kB]          
Get:21 lucid-updates/universe Packages [273kB]    
Get:22 lucid-security/main Packages [426kB]        
Get:23 lucid-updates/universe Sources [101kB]     
Get:24 lucid-updates/multiverse Packages [11.5kB] 
Get:25 lucid-updates/multiverse Sources [5,818B]  
Get:26 lucid-security/restricted Packages [2,855B]  
Get:27 lucid-security/main Sources [127kB]
Get:28 lucid-security/restricted Sources [1,259B]
Get:29 lucid-security/universe Packages [133kB]
Get:30 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