bash for loop: apt-get Linux system update and upgrade

Here’s a little bash gem for updating Ubuntu (or, really, any apt-get box). Check out the sweet bash for loop:

sudo bash -c 'for i in update {,dist-}upgrade auto{remove,clean}; do apt-get $i -y; done’

This single line bash command to runs a complete apt-get update that’s essentially a one line compression of this multi-line bash script:

 sudo -s -- <<EOF
 apt-get update
 apt-get upgrade -y
 apt-get dist-upgrade -y
 apt-get autoremove -y
 apt-get autoclean -y

from Ask Ubuntu – How to install updates via command line?

Scroll to Top