Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
My usual command for keeping the machine up to date is rather verbose, and it can result in more than one password prompt if any command takes a long time:
sudo apt-get update && sudo apt-get dist-upgrade && sudo apt-get autoremove && sudo apt-get autoclean
I'd like to shorten this down to one command (preferably without using a global alias).
Solution based on @amra's answer and another tip:
sudo sh -c 'apt-get update && apt-get upgrade --yes && if [ -f /var/run/reboot-required ]; then echo You should reboot; fi'
–
–
–
One can use the '&&' operator to execute command 'cmd2' if and only if 'cmd1' has been executed without errors:
(cmd1 && cmd2)
But this only works in bash directly, without 'sudo' in front.
So, in order 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"
Note that the answer proposed by amra does not the same as the above command:
Commands separated by ";" are executed in sequence without taking the exit code of the previous command into account.
When using "&&" to separate the commands, the exit code is taken into account.
Thus, if we have "cmd1 && cmd2", cmd2 is only executed if the exit code of cmd1 was 0 (i.e. cmd1 did not fail).
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.