Skip to content
TrySitePrice

How to run multiple commands in sudo under Linux or Unix

Best/Tutorial

You can run multiple commands as sudo by separating the commands with a semicolon (;) or by using a shell script.

  1. Using semicolon:
sudo command1 ; sudo command2 ; sudo command3
  1. Using a shell script:
rnCreate a shell script with the commands you want to run, make it executable and then run it with sudo:

#!/bin/bash

command1
command2
command3

chmod +x script.shrnsudo ./script.sh

Note: Running multiple commands as sudo can be dangerous, as it gives the commands elevated privileges. Make sure that the commands you run with sudo are safe and necessary.