Courses3 levels
Level 1 · Foundations11 courses
Level 2 · Core5 courses
Level 3 · Advanced5 courses
Labs8 topics
Library Practice exams AI Range Pricing Start free

Set-up · 15 minutes

Set up your Linux lab

After this lesson you can
  • Prepare a Linux shell that runs every lesson of the course
  • Create the lab folder ~/krlab/linux-basics
  • Prove with a check script that the lab is ready
Lab files of this lesson (1)

The lab folder as it stands after this lesson. Unzip it in ~/krlab.

More

The zip holds every file that the course has printed up to here. Type the code yourself first: you learn more.

What you need

Every task of this course runs on your own computer, in the folder ~/krlab/linux-basics. You attack and change nothing else. You need a computer with a Linux shell:

  • Linux. Any common distribution works. The lessons were written and tested on Ubuntu 24.04 LTS with bash and the GNU tools, and the output that they show comes from it. On a newer release, or on another family, some messages and the order of some lists differ. Open a terminal.
  • Windows. Use WSL (Windows Subsystem for Linux) with Ubuntu. In a PowerShell window that you started as administrator, run wsl --install, restart, and open the Ubuntu program. Work inside that window, and keep your lab files in the Linux home folder, not under C:.
  • macOS. The terminal is not Linux, and this course was tested on Linux only. Several commands differ on macOS, for example stat -c, sha256sum, touch -d and the format of ls -l. For this course, use a Linux virtual machine or a Linux server of your own.

You also need about 100 MB of free disk space. You need no network and no administrator rights, except where a lesson says that a step is only shown and not run. Two tools are optional: Midnight Commander (mc, lesson 7) and locate (lesson 8). The lessons say so where they use them.

Set it up

1. Open a terminal

Open the terminal program of your system. On an Ubuntu desktop press Ctrl+Alt+T, or search the applications for "Terminal". In WSL, open "Ubuntu" from the Start menu. On a server you are already in a terminal. The text that you see before the cursor is the prompt. This course shows commands without the prompt, so that you can copy them.

2. Make the lab folder

mkdir (make directory) creates a folder, and -p creates the folders above it too. cd (change directory) moves you into it. pwd (print working directory) shows where you are.

mkdir -p ~/krlab/linux-basics
cd ~/krlab/linux-basics
pwd
/home/you/krlab/linux-basics

The sign ~ is the short name for your home folder. Every lesson starts from this folder.

3. Write the check script

A script is a text file of commands. The script below has one function, check, that runs a command and prints ok or MISSING for it. It counts how many checks passed, prints the last line, and exits with a failure code if one check failed. You do not need to understand each part yet: Part 2 explains how such a script works.

Save the text as labcheck.sh in the lab folder. The easiest way is a terminal editor: type nano labcheck.sh, paste the text (in most terminals Ctrl+Shift+V), press Ctrl+O and Enter to save, and Ctrl+X to leave. Lesson 7 teaches the editors. You can also take the file from the lab files of the course. Save the zip in ~/Downloads. If unzip is missing, install it with sudo apt install unzip. unzip opens a zip file, and sudo runs one command with administrator rights (lesson 10). Run cd ~/Downloads && unzip files.zip && cd linux. The sign && runs the next command only if the one before worked (lesson 3). Then run sh kr-lab.sh 1-basics/00-set-up-your-lab ~/krlab/linux-basics. The same command with another lesson folder builds the lab as it stands after that lesson.

labcheck.sh

#!/usr/bin/env bash
# labcheck.sh - checks that this machine can run Part 1 of the Linux course (basics).
ok=0
total=0

check() {
    local name=$1
    shift
    total=$((total + 1))
    if "$@" > /dev/null 2>&1; then
        ok=$((ok + 1))
        echo "ok       $name"
    else
        echo "MISSING  $name"
    fi
}

check "bash" command -v bash
check "nano" command -v nano
check "vim or vi" bash -c 'command -v vim || command -v vi'
check "less" command -v less
check "grep" command -v grep
check "find" command -v find
check "tar" command -v tar
check "gzip" command -v gzip
check "xz" command -v xz
check "file" command -v file
check "sha256sum" command -v sha256sum
check "lab folder" test -w "$HOME/krlab/linux-basics"

echo "lab ready: $ok of $total"
(( ok == total ))

Check your lab

Run the script with bash. This way it needs no execute bit (lesson 10 explains that bit).

bash labcheck.sh
ok       bash
ok       nano
ok       vim or vi
ok       less
ok       grep
ok       find
ok       tar
ok       gzip
ok       xz
ok       file
ok       sha256sum
ok       lab folder
lab ready: 12 of 12

Each line is one requirement, and the last line is the result. Type the last line of your own run.

If it fails

A line that starts with MISSING names what is absent. Fix it, and run the script again.

LineWhat to do
nano, vim or vi, lessOn Debian and Ubuntu: sudo apt install nano vim less. On Fedora: sudo dnf install nano vim less.
grep, findsudo apt install grep findutils, or sudo dnf install grep findutils.
tar, gzip, xzsudo apt install tar gzip xz-utils, or sudo dnf install tar gzip xz.
filesudo apt install file, or sudo dnf install file.
sha256sumIt is part of coreutils, which every Linux has. On macOS use shasum -a 256.
lab folderGo back to step 2. Check that the folder is yours with ls -ld ~/krlab/linux-basics.

If the last line says lab ready: 11 of 12, the lab works for every lesson that does not need the missing part. Read the lessons that use that part first, and fix it before you start them. If you cannot use sudo on your machine, ask the person who owns the machine, or use your own virtual machine. Do not change a system that is not yours.