rasti.hil@hilandco.com +41 79 367-9677

Search This Blog

How to Execute Multiple Commands Using a Single sudo

 

sudo sh -c 'cmd1; cmd2'


The semicolon (;) serves as a special character, enabling us to segregate multiple commands within a single line. sudo sh -c 'cmd1 & cmd2'

The ampersand (&)triggers the commands to run concurrently, or simultaneously.

sudo sh -c 'mkdir DIR && cp -r $USER/* DIR'

The AND operator (&&) is employed to execute commands only if both of the specified conditions are true.


sudo sh -c 'apt-get install foo || apt-get update'

The || operator guarantees that the second command executes only if the first command fails.


sudo -- sh -c 'cmd1 & cmd2'

The double dash (--) signifies that sudo should halt processing command line arguments and interpret the remaining arguments as the command to execute.