Apt-get update, dist-upgrade, autoremove, autoclean in one sudo command

My usual command for maintaining the machine’s health is quite detailed and can lead to several password requests if any command takes a lot of time:

sudo apt-get update && sudo apt-get dist-upgrade && sudo apt-get autoremove && sudo apt-get autoclean 

I would like to shorten this to a single command (preferably without using a global alias).

@Amra answer based solution and one more tip :

 sudo sh -c 'apt-get update && apt-get upgrade --yes && if [ -f /var/run/reboot-required ]; then echo You should reboot; fi' 
+7
ubuntu apt-get
source share
2 answers

Try

 sudo sh -c "apt-get -y update;apt-get -y dist-upgrade;apt-get -y autoremove;apt-get -y autoclean" 
+16
source share

You can use the '& &' operator to execute the cmd2 command if and only if cmd1 was executed without errors:

 (cmd1 && cmd2) 

But this only works in bash directly, without the "sudo" in front.

So, to work as expected, we can use the following command:

 sudo /bin/sh -c "apt-get update && apt-get dist-upgrade && apt-get autoremove && apt-get autoclean" 

Please note that the answer proposed by amra does not match the command above: Commands separated by the ";" are executed sequentially, not taking into account the exit code of the previous command. When using & & to separate commands, the exit code is taken into account. Thus, if we have "cmd1 & cmd2", cmd2 is executed only if the exit code of cmd1 is 0 (i.e. Cmd1 is not interrupted).

+1
source share

All Articles