Your DevOps study space

Real explanations. Videos with tests. Fresh exams every time. Keep the streak alive and watch the XP stack up.

Environment & shell setup · Linux Docs · StackwisePlanDevOps Environment & shell setup · Linux Docs · StackwiseCodePython Environment & shell setup · Linux Docs · StackwiseBuildDocker Environment & shell setup · Linux Docs · StackwiseTestDevOps Environment & shell setup · Linux Docs · StackwiseReleaseGit Environment & shell setup · Linux Docs · StackwiseDeployKubernetes Environment & shell setup · Linux Docs · StackwiseOperateLinux Environment & shell setup · Linux Docs · StackwiseMonitorDevOps

Pick a topic

Eight tracks, each with docs, a cheat sheet, videos and tests.

How it works

One loop, repeated until it sticks.

Jump back in

Picked up from where you left off.

Free forever

Your DevOps journey starts with one click.

Sign in with Google or GitHub to open every chapter, video, test and challenge. Your progress is saved wherever you learn.

Environment & shell setup

Why does a command work in one terminal but not another, or on your laptop but not in cron or with sudo? Almost always the answer is the environment: which variables are set, what PATH contains, and which startup files your shell read. This chapter explains all three, plus the aliases and shortcuts that make the shell pleasant to use.

Shell variables vs environment variables

A plain assignment creates a shell variable: only the current shell can see it. export turns it into an environment variable, which is copied into every program the shell starts from then on.

$ GREETING=hello
$ bash -c 'echo "child sees: [$GREETING]"'
child sees: []
$ export GREETING
$ bash -c 'echo "child sees: [$GREETING]"'
child sees: [hello]
$ declare -p GREETING          # -x means exported
declare -x GREETING="hello"
$ unset GREETING               # remove it again

Two more rules explain a lot of confusion:

  • DEBUG=1 ./app.sh sets the variable for that one command only, without changing your shell.
  • The copy only goes downwards. A child process can never change its parent's variables, which is why a script that runs export or cd has no effect on your terminal after it finishes. To change the current shell, you source the file instead (see below).

Seeing the environment

$ printenv PATH               # one variable
$ printenv | sort | less      # all exported variables
$ env | grep -i proxy         # env with no arguments also lists them
$ env -i bash --norc          # a shell with an (almost) empty environment, for testing
$ set | less                  # shell variables AND functions too, not just exported ones

Variables you'll meet constantly: HOME (your home folder), USER, PWD (current folder), SHELL (your login shell), EDITOR (used by crontab -e and git commit), LANG (language and character encoding) and PATH.

PATH and how a command is found

When you type python3, bash checks in this order: is it an alias? a shell keyword (if, for)? a function? a builtin (cd, echo, export)? Only then does it search the folders in PATH from left to right and run the first match. If nothing matches: command not found.

$ python3alias?nokeyword?nofunction?nobuiltin?nothen the folders in $PATH, left to right:/usr/local/sbinnot here/usr/local/binnot here/usr/sbinnot here/usr/binfound!first match wins: /usr/bin/python3 runs
That order is why an alias can hide a program, and why the same name in two PATH folders runs the one listed first. type -a shows every match.
$ echo "$PATH"
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
$ type ls
ls is aliased to `ls --color=auto'
$ type cd
cd is a shell builtin
$ type python3
python3 is /usr/bin/python3
$ type -a python3        # every match, in PATH order
$ which python3          # searches PATH only
/usr/bin/python3
$ which cd               # prints nothing: cd isn't a file, it's built into bash
$ command -v docker      # script-friendly "is it installed?" check

Prefer type when debugging "why is the wrong version running?", because it also sees aliases and functions that which can't. Because the first match wins, the order matters: to use your own tools ahead of the system's, add their folder to the front:

export PATH="$HOME/.local/bin:$PATH"    # prepend, keep everything that was there
Writing export PATH=~/bin (without :$PATH) replaces the whole list, and suddenly even ls is "command not found". Just open a new terminal, or run export PATH=/usr/local/bin:/usr/bin:/bin to get going again, then fix the line in your startup file.

Bash also remembers where it found each command. If you install a new version in a different folder and the old one still runs, hash -r clears that memory. And note that sudo resets most variables and uses its own fixed PATH (secure_path in /etc/sudoers), so tools in ~/.local/bin are "not found" under sudo unless you give the full path.

Startup files: ~/.bashrc vs ~/.profile

Which files bash reads depends on how it was started:

FileRead byPut here
~/.profilelogin shells: SSH sessions and console logins (Ubuntu's graphical login reads it too)environment variables and PATH changes
~/.bashrcevery interactive bash that isn't a login shell, like a new terminal window on a desktopaliases, functions, prompt, history settings
/etc/profile, /etc/bash.bashrcthe system-wide versions, read before yourssettings for all users (needs sudo)

On Ubuntu the default ~/.profile also sources ~/.bashrc, so SSH logins get your aliases too, and it already adds ~/bin and ~/.local/bin to PATH if those folders exist. Scripts (non-interactive shells) read neither file, and Ubuntu's ~/.bashrc stops at its first lines when the shell isn't interactive.

If a ~/.bash_profile exists, login shells read it instead of ~/.profile. Creating one "to add a PATH line" silently disables everything in ~/.profile. On macOS the default shell is zsh, whose files are ~/.zprofile and ~/.zshrc.

Sourcing: apply changes now

Editing ~/.bashrc changes nothing in terminals that are already open, because they read it when they started. Re-read it in the current shell with source (or its short form, a dot):

$ source ~/.bashrc
$ . ~/.bashrc            # exactly the same thing

Running bash ~/.bashrc or ./file would execute it in a child process, which then exits and takes its settings with it.

Aliases and small functions

alias ll='ls -alF'                       # Ubuntu's .bashrc already defines ll, la and l
alias k='kubectl'
alias gs='git status'
alias ports='sudo ss -tulpn'

mkcd() { mkdir -p "$1" && cd "$1"; }     # functions can take arguments

$ alias                  # list all aliases
$ unalias k              # remove one
$ \ls                    # run the real ls, skipping the alias

Put them in ~/.bashrc, or in ~/.bash_aliases, which Ubuntu's .bashrc loads automatically if it exists. Aliases are not expanded in scripts, so use full commands (or functions) there.

.env files

Apps usually read secrets and settings from environment variables, and a .env file is a simple list of them kept next to a project:

# .env
DB_HOST=localhost
DB_PORT=5432
API_KEY=change-me

Docker Compose reads a .env file in the project folder automatically, Python has python-dotenv, Node has dotenv, and systemd services can load one with EnvironmentFile=. To load one into your current shell:

$ set -a            # auto-export every variable assigned from now on
$ source .env
$ set +a            # back to normal
$ echo "$DB_HOST"
localhost
A .env file usually contains secrets: add it to .gitignore, give it chmod 600, and commit a .env.example with dummy values instead so others know which variables exist.

History tricks and shortcuts

$ history 20         # last 20 commands, numbered
$ !42                # rerun command number 42
$ !!                 # rerun the last command (sudo !! = again, with sudo)
$ vim /etc/nginx/nginx.conf
$ sudo nginx -t -c !$      # !$ = last argument of the previous command

Ubuntu's .bashrc sets HISTCONTROL=ignoreboth, which skips duplicate lines and any command that starts with a space. Typing a space first is a handy way to keep a command with a password in it out of ~/.bash_history.

KeysDoes
Ctrl+Rsearch history backwards as you type; Ctrl+R again for older matches, Enter runs it, Ctrl+G cancels
Tab / Tab Tabcomplete a command or path / list the possibilities
Ctrl+A / Ctrl+Ejump to start / end of the line
Ctrl+W / Ctrl+U / Ctrl+Kdelete the previous word / everything before the cursor / everything after it
Ctrl+Ypaste back what the last delete removed
Alt+.insert the last argument of the previous command
Ctrl+Lclear the screen
Ctrl+C / Ctrl+Dcancel the current command / log out (on an empty line)

cd - jumps back to the previous folder, which pairs nicely with all of the above.

Questions

Pick an answer. Get it wrong and you can try again right away, no waiting. 10 questions per topic - pick a filter below, then use Recreate questions for a fresh set on that topic.

Fresh questions every time

Exam

A mixed test across the whole site, shuffled so you never know which topic comes next. When you submit, every mistake comes with the reason and a jump to the exact moment in the video that explains it.

30 questions 6 topics 20 minute limit Up to 70 XP
1–4 answer · ←→ move
History

Essay

0 / 200-250 words
Sample answer
History
0:00 / 0:00
Not started

on YouTube
Subscribe

Topic progress

Activity

Achievements

Settings

Your profile and your account.

Profile details

* Required. Saved in this browser until you sign in.

Letters, numbers, dots, dashes and underscores.
0 / 160

Account

Checking…

App

Install Stackwise on your phone or computer. It opens in its own window from your home screen, and the Docs and cheat sheets you've opened keep working without internet.

Only admins can see this

Dashboard

Sign-ups, activity, messages and reviews in one place.

Prove it

Certificates

Pass a topic's test and get a certificate with its own public page you can share or add to LinkedIn. Each test is 10 questions drawn at random and graded on the server; you need 8 right, you have 15 minutes, and you get one try per topic a day.

From first command to production

Linux for DevOps

A path through Linux the way DevOps engineers use it: ten stages, every command explained with its flags, examples, real output and mistakes, the combinations engineers chain together, and incidents worked through step by step. Practise everything in a safe lab folder.

Before the interview

Interview prep

Questions that come up in real DevOps interviews, with the kind of answer that lands. Say yours out loud first, then compare. Each one links to the chapter that goes deeper.

    Private to you

    My notes

    Everything you wrote down while watching and reading, in one place. Saved to your account, never shown to anyone.