Example uses of the command "sudo"

A Brief Introduction

Man sitting at desk using computer
Andersen Ross/Stockbyte/Getty Images

The sudo command is frequently used to execute a command that requires root privileges. For example, if you want to run a shell script setup.sh that installs a program into a directory that only root can modify you can use sudo as follows:

sudo -u root ./setup.sh
You may be required to enter the root password before the command is executed. After you have logged in, you can continue to execute commands through sudo for a few minutes without having to specify the login (-u root) with every command.
If possible, it is better to do your regular work using an account with restricted privileges to avoid causing serious damage to the system by accident. You can list the files of a protected directory with the following command:
sudo ls /usr/local/classified
Use the following line to reboot the system in 20 minutes:
sudo shutdown -r +20 "rebooting to fix network issue"
See also: sudo
Was this page helpful?