Skip to content

Linux Basics


At the end of this self-learning lab, you should be able to:

  • Access the command line interface in Linux
  • Find out the meaning of some commands by yourself

What is Linux?

  • Linux is an operating system (OS) like Windows and MacOS, which is the layer that runs all user applications and coordinates hardware like CPU and memory.
  • There are many different distributions of Linux, and Ubuntu is one of them. In M2 (as of 2020-2021), we use Ubuntu 20.04 (Focal Fossa), and you are strongly recommended to use the same version.

Command Line Interface (CLI)

Why do I have to use command line interface?

so that girls will think you're cool

Graphical user interface (GUI) is much more complex to write than CLI, and requires many other drivers and OS integrations, including mouse drivers, windowing and much more.

CLI is an abstract interface where you can type a command, which instructs the OS to start a process. Then the CLI will show you the output from the process ("stdout" + "stderr") and send your input to the process if the process asks for any.

This means you are asked to type the command echo Hi in the terminal, and we expect the terminal to show Hi.


CLI is an abstract interface, which means it can appear anywhere that has input and output capabilities. In the most ancient days, terminals were implemented by typewriters and hole punchers!

In Ubuntu 20.04 Desktop (the recommended version you installed in VirtualBox), you can open a terminal anytime using Ctrl-Alt-T, which provides a window that emulates a CLI.

Some robots have a screen installed, on which we can see the boot terminal output. However, we usually use a remote connection to connect to robots, which will be explained later.

Shells and commands

Most of the time, commands are run through a process which we call "shell process". When we open a terminal, it actually starts a "shell process" (usually /bin/bash) and pass all our input to the shell process and show the shell process output.

The shell process actually preprocesses the command before sending it to the OS. Special characters like ;, &&, ~, $, ", etc. have special effect on the shell.

There are also some commands that are only processed by the shell, such as cd and exit. These commands are not passed into the OS, and you cannot find a command file called cd in your PATH.

Furthermore, there are some "shell aliases" which are registered in "bashrc" files, e.g. l is automatically changed to ls in many default bashrc setups.

In general this does not matter, but keep this in mind when you try to run a subprocess by command line programatically (e.g. the Python subprocess.spawn function) without allocating a shell.

A few notations

In this section (and most other sections of this site), we will show the terminal in this format:

## This command outputs the line "Hi"
$ echo Hi

This means you are asked to type the command echo Hi, which will give the output Hi. Lines starting with ## are "comments", which are just some prose to explain the commands to you.

You often need to use the Ctrl/ key to send signals to a process. We use ^ to indicate the key. For example, ^C means Ctrl-C/-C (without Shift), and ^B-D means press Ctrl-B/-B, then press D separately.

Checking the commands to use

Nobody really "remembers" all commands by heart. There are thousands of commands in a default installation, and many commands have dozens of options. Instead, we always check the documentation.

Method 1: Use the man command.

Try running the command man ls in the terminal. You will see a fullscreen manual page explaining the command ls:

LS(1)                           User Commands                           LS(1)

       ls - list directory contents

       ls [OPTION]... [FILE]...

       List  information  about the FILEs (the current directory by default).
       Sort entries alphabetically if none of -cftuvSUX nor --sort is  speciā€

... (omitted)

You can scroll up or down using the arrow keys and PgUp PgDn Home End. Exit the manual page with Q.

Most essential commands have a man page with the command name. However, some man pages are named by their package name instead.

Method 2: Search online

In particular, results from askubuntu/superuser/stackoverflow are usually helpful.

Method 3: M2 wiki

If you are dealing with some setup problems that our programmers often have to deal with, it is likely that your problem is already documented in the M2 wiki.

Never be embarrassed about not remembering some command!

In the next section we will go through some must-know commands.