How to run a command or script after running apt-get command on a Debian or Ubuntu Linux

How to run a command or script after running apt-get command on a Debian or Ubuntu Linux

If you want to run a command or script after running apt-get on a Debian or Ubuntu Linux system, you have a few different options:

  1. You can use the && operator to chain the two commands together, like this:
refe‮ r‬to:lautturi.com
sudo apt-get update && my_command

This will run the apt-get update command, and if it succeeds (i.e. returns a zero exit code), it will then run the my_command command.

  1. You can use the ; operator to separate the two commands, like this:
sudo apt-get update; my_command

This will run the apt-get update command and then run the my_command command, regardless of the exit code of the apt-get update command.

  1. You can use the bash&& operator in a script, like this:
#!/bin/bash
sudo apt-get update && my_command

Save the script, make it executable with chmod +x script.sh and then run it with ./script.sh.

  1. You can use the bash; operator in a script, like this:
#!/bin/bash
sudo apt-get update; my_command

Save the script, make it executable with chmod +x script.sh and then run it with ./script.sh.

Created Time:2017-10-29 22:08:36  Author:lautturi