Stage 03 · Lesson 02/14

Linux & Dev Environment · Lesson 02

Linux Terminal Fundamentals

Est. 35–45 min

Why

Why the terminal is your robot’s front counter

Every robotics session starts in a terminal: go to the project folder, start a driver, watch a log, SSH into the robot. In this lesson you learn to read the prompt, move around the file system, and use the shortcuts that make you quick.

Concept

The big idea: prompt, command, options, arguments

When you open a terminal you see a prompt. It tells you who you are, which machine you are on and where you are standing.

Reading the prompt ashish@robot-lab:~/robot_ws$
PartMeaning
ashishYour user name (whoami)
@robot-labMachine name (hostname) — very useful when you SSH into the robot and forget which window is which
~/robot_wsCurrent directory. ~ is short for your home folder, /home/ashish
$Normal user. A # means you are root (super-user) — be extra careful

A command line has three parts: command, options (start with - or --) and arguments (what to act on).

ls -l /dev

  • ls = command (list)
  • -l = option (long format)
  • /dev = argument (which folder)
Your first ten commands
CommandWhat it doesRobot example
pwdPrint where you areAm I in the robot workspace?
ls / ls -l / ls -aList files / long details / include hiddenFind bringup.sh, see .venv
cd folderGo into a foldercd robot_ws/scripts
cd ..Go up one levelBack to the workspace root
cd ~ or cdGo homeLost? Go home
cd -Jump back to the previous folderToggle between src and logs
cat filePrint a fileRead config/robot.yaml
clear (Ctrl+L)Clean the screenBefore a demo
man ls / ls --helpBuilt-in manualWhat does -h do?
historyCommands you typed earlierRepeat yesterday’s bring-up

How it works

How it actually works: shortcuts that save hours

  1. Tab completion

    Type cd rob and press Tab — bash completes robot_ws/. Press Tab twice to see all choices. Fewer typos in long paths like /dev/ttyUSB0.

  2. Up arrow / history

    Press ↑ to bring back the last command. Ctrl + R then type bring searches your history for the last bring-up command.

  3. Ctrl + C

    Stops the program running in the foreground. Your first emergency brake for a runaway script (the real brake for motors is still the hardware e-stop).

  4. Ctrl + L

    Clears the screen but keeps history.

  5. Copy and paste

    In most Linux terminals it is Ctrl + Shift + C / Ctrl + Shift + V. Plain Ctrl + C means “stop”, not copy!

Visual

Visualise it: practise in a safe terminal

Practise pwd, ls, cd, cd .., cat, mkdir and touch on a fake robot home folder. Nothing here touches your real computer.

Interactive · Terminal simulator

# robotics workstation simulator
# try: pwd · ls · cd workspace · cat robot_controller.py

cwd: /home/robot · simulated only

Worked example

Worked example: walking through a workspace

Ravi opens a fresh terminal. Follow each line and predict the answer before reading the right column.

Ravi typesTerminal answersWhy
pwd/home/raviTerminals start in your home folder
lsDownloads robot_wsTwo folders here
cd robot_ws(nothing)Silence means success in Linux
pwd/home/ravi/robot_wsHe moved one level down
cd ..(nothing)Up one level
cd robotbash: cd: robot: No such file or directoryTypo — Tab completion would have saved him

Code lab

Code lab: your first walk (safe, inside /tmp)

Save this as terminal_basics.sh and run bash terminal_basics.sh. It only creates folders under /tmp/aihub-lab, a scratch area that is cleared on reboot.

terminal_basics.sh · Shell
#!/usr/bin/env bash
# terminal_basics.sh — first walk around the terminal (Lesson 2)
# Safe: it only creates folders inside /tmp/aihub-lab
mkdir -p /tmp/aihub-lab/robot_ws/src /tmp/aihub-lab/robot_ws/logs
cd /tmp/aihub-lab
pwd
ls
cd robot_ws
pwd
ls
cd ..
pwd
echo "Namaste from $(basename "$PWD")"

Expected output

/tmp/aihub-lab
robot_ws
/tmp/aihub-lab/robot_ws
logs
src
/tmp/aihub-lab
Namaste from aihub-lab

Real world

Where you will use this every single day

  • On a Jetson you cd ~/robot_ws, ls scripts/ and start ./scripts/bringup.sh.
  • During a demo you keep one terminal for the controller and another for logs — the prompt’s hostname tells you which is the robot.
  • When something breaks at 11 pm before a college project review, history | grep bringup finds the exact command that worked yesterday.

Mistakes

Common mistakes and debugging

Hardware & safety

Hardware lab and safety notes

The terminal is how you will talk to a Raspberry Pi or Jetson that has no screen. Practise the same commands on real hardware when you can.

  • On a Pi: ls /dev once, plug an Arduino in, ls /dev again — spot the new ttyACM0.
  • Use history to see what you typed on the robot yesterday.
  • Never paste a command from the internet that starts with sudo until you understand every word of it.
Raspberry Pi 4 Model B single-board computer, top view
A Raspberry Pi with no screen is driven entirely from the terminal.Photo: Laserlicht · CC BY-SA 4.0 · Source: Wikimedia Commons · resized, converted to WebP

Debugging

Debugging: when it doesn’t work

Symptom → likely cause → fix
SymptomLikely causeFix
command not foundTypo, or the tool is not installedCheck spelling; press Tab to complete; install with apt (Lesson 6)
No such file or directoryWrong folder or wrong name (Linux names are case-sensitive)Run pwd and ls; Robot.py and robot.py are different files
Prompt shows > and waitsUnclosed quote " or 'Press Ctrl + C and retype the line
Copy-paste does nothingTerminal uses Ctrl + Shift + C / VUse Ctrl + Shift + V to paste in the Ubuntu terminal
NoteRead the last line of an error first — it usually names the problem. Change one thing at a time and re-run.

Think

Think about it

Think

Your script opens `config/robot.yaml` (a relative path). It works when you run it from `~/robot_ws` but fails from `~`. Why?

Experiment

Try it in the lab: terminal drills

Use the simulator above. Say each command’s meaning aloud before you press Enter.

Experiment

Terminal drills

You will need

  • Terminal simulator
  • Notebook

Steps

  1. Run `pwd`, then `ls`. Write down the folders you see.
  2. `cd logs`, then `pwd` again. Notice the path grew by one folder.
  3. `cd ..` and `cat robot_controller.py`. Find the stop distance in the file.
  4. `cd workspace/scripts` and `cat bringup.sh`.
  5. Type a command that is not allowed (for example `rm`) and read how the whitelist rejects it.

Interactive · Terminal simulator

# robotics workstation simulator
# try: pwd · ls · cd workspace · cat robot_controller.py

cwd: /home/robot · simulated only

The cwd: line under the simulator always shows where you stand. If cat says “No such file”, run ls first — you are probably in the wrong folder.

Knowledge check

Check your understanding

Knowledge check

1. `pwd` tells you…

2. `cd robot_ws` then `ls` is useful to…

3. If a command is not on the simulator whitelist…

4. In `ls -l /dev`, the `-l` part is…

5. In a Linux terminal, Ctrl + C usually…

Mini assignment

Hands-on assignment

Mini assignment

Command cheat card

Make a pocket cheat card you will actually keep next to your laptop.

Deliverables

  • Ten commands from this lesson, each with one robotics example
  • The prompt `ashish@robot-lab:~/robot_ws$` labelled part by part
  • Three keyboard shortcuts you will use daily

Do this, step by step

  1. In the simulator, run pwd, ls, cd robot_ws, ls -l and cd ..; write each answer.
  2. On a real terminal, run terminal_basics.sh and compare with the expected output.
  3. Press ↑ three times, then try Tab completion on a long folder name; note what happened.
  4. Make your cheat card: 10 commands, each with one robotics use.

Stuck? Hints, one at a time

NoteTry the task first. Read one hint, try again, and only then read the next one.
  1. Hint 1: pwd = where am I; ls = what is here; cd = go there. Every other command builds on these three.
  2. Hint 2: Label the prompt ashish@robot-lab:~/robot_ws$ as user @ host : folder, with $ meaning a normal (non-root) user.
  3. Hint 3: Good robotics uses: tail -f for live logs, ls /dev for ports, cat for a config file.

Challenges (pick by level)

  • 🟢 Easy: Use man ls to find the option that sorts by time; try it.
  • 🟡 Medium: Create ~/robot_ws/notes.txt with echo and >> and read it back with cat.
  • 🟠 Hard: Use history | grep cd to find every folder you visited today.

Next step

Look back: Lesson 1: Why Linux for Robotics. Next: Lesson 3: Files & Directories. Related: Stage 2 — Python Fundamentals.

Sources

Self-attested for now — keep artifacts in your lab notebook.

Complete

Today's goal

0 of 1 done today

0-day streak
Daily goal:lessons, quizzes or assignments a day

Mark this lesson complete when you have worked the experiment, knowledge check, and assignment (even roughly).

Stuck somewhere?

Ask a doubt about this lesson

Saved with this lesson's id and your email so we can reply. Privacy · or email contact@aihubstation.in