CodeTheRobot

Ubuntu Linux for Robotics · Lesson 20 of 96

Aliases and productivity tools

Aliases, functions, history search, tmux and small habits that save hours.

Estimated time · 30–45 min

Learning goals

What you will understand

  • Explain aliases and productivity tools in your own words
  • Use it in a small workstation example
  • Verify the result instead of assuming it worked

Understand the idea first

The mental model

An alias is a short name for a longer command: alias cb='colcon build --symlink-install'. Put aliases in ~/.bashrc. For anything with arguments write a shell function instead. Ctrl+R searches your command history, Ctrl+A/Ctrl+E jump to line start and end, and !! repeats the last command.

tmux keeps several terminals in one window and keeps them alive if your SSH connection drops, which is important for long builds on a robot. Detach with Ctrl+B then D and reattach with tmux attach. Use aliases for convenience, but write real commands in documentation and scripts so others can follow them.

Guided lesson

Work through these steps

  1. 1.

    Open a terminal and record the current state before changing anything.

  2. 2.

    Read the aliases and productivity tools commands and predict what each one does.

  3. 3.

    Run the commands one at a time and compare each output with your prediction.

  4. 4.

    Write the commands that worked in a setup note you can repeat later.

Worked example

Read it before you run it

alias cb='cd ~/robot_ws && colcon build --symlink-install && source install/setup.bash'
# One short command to build and source the workspace.
alias ll='ls -alFh'
# A detailed listing shortcut.
mkcd() { mkdir -p "$1" && cd "$1"; }
# A function: create a folder and enter it.
history | grep colcon
# Find earlier commands that mention colcon.
tmux new -s build
# Start a persistent terminal session called build.
tmux attach -t build
# Return to it later, even after reconnecting.

What the example is doing

  1. 1.Lines without sudo only inspect or change files you own; sudo authorizes a system-wide change.
  2. 2.Read command output before moving to the next line. Stop if names, versions, disks, or paths differ from the lesson.
  3. 3.Comments beginning with # explain safety checks and are not executed by the shell.

Watch it run · Build and run

See what this code does

The terminal types this lesson's practice solution and runs it. The scene shows the kind of robot behaviour that code drives. It plays by itself and loops.

sourcecompilerprogramBUILD AND RUN

Demo for Aliases and productivity tools. Expected result: The alias cb builds and sources the workspace in every new terminal

Practice code

Now type it yourself

Open a terminal, run the starter line by line (or save it as practice.sh and run bash practice.sh), and replace every TODO with your own command.

# TODO: append the alias line for cb to ~/.bashrc and reload the file
type cb

Expected output

The alias cb builds and sources the workspace in every new terminal
Stuck? Show the full solution (try it yourself first)
echo "alias cb='cd ~/robot_ws && colcon build --symlink-install && source install/setup.bash'" >> ~/.bashrc
source ~/.bashrc
type cb

Expected result

How you know it worked

  • Each command completes without an unexplained error.
  • Your notes contain the command, the important output, and what it proves.

Practical exercise

Apply the lesson

Add three aliases and one function to ~/.bashrc (build, source, and a function that creates a package folder), reload the file, and run a long command in tmux that keeps running after you close the terminal window.

Before you continue

  • You recorded the starting state
  • Every command and output is understood
  • The change can be repeated from your notes

If something goes wrong

A command says permission denied.

Check ownership and permissions first. Do not add sudo unless the command changes a documented system location.

A command or package is not found.

Check spelling, Ubuntu version, enabled repositories, and whether the previous installation command succeeded.