Faster Learning Tutorials

Linux sudo command summary with examples

sudo allows you to run a command as superuser.
  1. Purpose - Learn what sudo is for and how to find help.
  2. Options - Review a few common options and arguments.
  3. Examples - Walk through code examples with sudo.
  4. A tip - Finish off with one more insight.
Paul Alan Davis, CFA, November 9, 2016
Updated: August 5, 2018
In this tutorial, 79 of 100, below find a 3-4 minute introductory video, a text-based tutorial and all of the code examples from the video.

Outline Back Next

~/ home  / tech  / linux essentials  / sudo command

The Linux sudo command


Learn to run a command as a superuser at the Linux command line.

Video Tutorial

Linux sudo command summary with examples (3:41)

Videos can also be accessed from the YouTube Playlist.

Video Script

The Command and Why You Need It

Our seventy-ninth word, or command to memorize is sudo from our category Users.

sudo allows you to run a command as superuser.

Recall from the previous video (tutorial) on su we logged in as another user. Now we'll take a superuser role temporarily to run commands as an administrator, also known as a superuser.

Before we start, it helps to think of commands as mini programs and most follow this structure: command -option(s) argument(s).

The sudo command has 25 options, and the argument is the command to execute or a file to open.

Like most commands, help is available with double-dash --help. For files, the -e command goes right in to a default editor, and -l lists what you can do, assuming you are a superuser.

So why is sudo an important command? Well, we need to limit access to adminstrative duties like installing software, viewing logs and configuration files. And now you know how to do that.


Okay, the best way to embed this in your memory is by typing in your own terminal window.

Find this on your Mac using a program called Terminal. On Linux use Terminal or Konsole, and currently Microsoft is adding this functionality to Windows.

Here we go. Let's say I have a backup script called video79.script that Jennifer wants to run periodically, so I'll make her a copy.

$ ls -og video79.script -rw-r--r-- 1 0 Nov 9 17:14 video79.script

First, do a cp video79.script /home/jennifer.

$ cp video79.script /home/jennifer cp: cannot create regular file '/home/jennifer/video79.script': Permission denied

And notice, an error. I can't access others' directories unless I'm superuser, so add sudo on the front.

$ sudo cp video79.script /home/jennifer

And there we go.

Then, let's do an ls -og for permissions, or mode, from video (tutorial) #75.

$ ls -og /home/jennifer total 0 -rw-r--r-- 1 0 Nov 9 18:35 video79.script

And she can't execute this right? So let's do a sudo chmod 500, from the octals in video (tutorial) #75, with 5 for read and execute, applying to the owner only, and 0 0 for the others.

$ sudo chmod 500 /home/jennifer/video79.script

And then last, let's give her ownership with a sudo chown jennifer the owner, :jennifer the group, then the file name and there we go. Then let's do an ls -l to verify we have done everything correctly here.

$ sudo chown jennifer:jennifer /home/jennifer/video79.script $ ls -l /home/jennifer total 0 -r-x------ 1 jennifer jennifer Nov 9 18:35 video79.script

Very good.

A Final Tip

Okay now you know how to use sudo. And you know the syntax for commands, options and arguments.

One last tip about the sudo command. So please make some time to practice these commands it does take a little bit of work, and next, we'll learn about passwords.

Okay, thanks for visiting today. I hope this was a helpful introduction to the sudo command.

Learn More About The Series

For an overview of the 100 videos, the 8 quizzes, a cheat sheet, the categories and a Q&A section, visit:

What's Next?

If you'd like to be notified of new YouTube videos, subscribe here.

  • For the Outline to all 100 tutorials, click Outline.
  • To go back to the su command, hit Back.
  • To learn how regular users and superusers change passwords with the passwd command, click Next.

Outline Back Next

~/ home  / tech  / linux essentials  / sudo command

linux sudo command
man sudo
etc sudoers
sudoers file
sudo command example
linux super user
root privilege
linux root
root user
superuser root
linux administration
linux system administrator
sudo su