sudo runs a single command with administrator rights. Learn exactly what changes, why it has no effect on `>`, and why `sudo tee` exists, by running the commands in a real terminal in your browser.
Updated: 2026-09-07
sudo command
Runs that one command as the administrator (root).
You are logged in as user.
$ whoami
user
System logs are not readable by an ordinary user.
$ cat /var/log/auth.log
cat: /var/log/auth.log: Permission denied
With sudo, they are.
$ sudo cat /var/log/auth.log
Sep 7 09:00:01 webterm sshd[456]: Accepted publickey for user from 192.168.1.10
Sep 7 09:14:22 webterm sudo: user : COMMAND=/usr/bin/systemctl restart nginx
That log is itself the record of who ran what through sudo.
Only who runs that command.
$ sudo whoami
root
$ whoami
user
sudo whoami answers root, and the very next whoami is back to user.
The elevation lasts exactly one command.
If the destination belongs to root, even a copy fails.
$ cp index.html /var/www/html/
cp: cannot create '/var/www/html//index.html': Permission denied
$ sudo cp index.html /var/www/html/
$ ls -l /var/www/html
total 4
-rw-r--r-- 1 root root 15 Sep 7 17:17 index.html
Files created through sudo belong to root.
If you will want to edit one later, hand it back with sudo chown user:user file.
Services work the same way.
$ sudo systemctl restart nginx
$ systemctl is-active nginx
active
This is the classic trap.
$ echo '10.0.0.1 db' >> /etc/hosts
zsh: permission denied: /etc/hosts
Writing sudo echo '10.0.0.1 db' >> /etc/hosts changes nothing, because the >> is carried out by your shell; sudo only reaches echo.
tee moves the writing into the elevated program.
$ echo '10.0.0.1 db' | sudo tee -a /etc/hosts
10.0.0.1 db
$ cat /etc/hosts
127.0.0.1 localhost
10.0.0.1 db
sudo tee -a is the standard way to add a line to a system file.
sudo is what you type to touch something that is not yours.
| Situation | What to type |
|---|---|
| Read a system log | sudo cat /var/log/auth.log |
| Restart a service | sudo systemctl restart nginx |
| Place a file where it is served from | sudo cp index.html /var/www/html/ |
| Add a line to a system config | echo "..." | sudo tee -a /etc/hosts |
| Install a package | sudo apt install tree |
sudo stops at the command.
Redirection (>, >>), the right-hand side of a pipe and ~ expansion are the shell's work.
Nearly every "I used sudo and it still failed" is this.
Files made with sudo belong to root.
Later you find you cannot edit your own deployment.
Check the owner with ls -l and hand it back with chown when needed.
Read the target once more before pressing enter.
With sudo in front, system files are within reach.
For anything irreversible such as rm -rf, check the path with your finger on the screen first.
webterm.appthis site
Advanced Terminal Commands
Learn commands for specific situations
learn.webterm.appa separate site

Commands stick when they show up in a real sequence of work, not one at a time. There is a course that builds them up in order.
See the course