Operating System: Linux/Ubuntu for ROS2

ROS stands for Robot Operating System. However, it extends a classical Operating System, specifically a Linux/Ubuntu OS.

The goal of this tutorial is to revisit basic Operating System concepts, focusing mainly on the Shell, which offers the simplest way to interact with your computer.


Play with Linux

Ubuntu is a Linux distribution (Operating System + Window Management + Tools) derived from the Debian distribution, within the galaxy of Open Source solutions.

  • Open Source means that every user can access the source code of the programs (open source is not necessarily free of charge).
  • Linux is mostly an OS kernel. It exposes computer capabilities (computing, memory access, and other devices) to developers. The C/C++ programming languages were developed for the Linux kernel.
  • Distribution refers to an OS kernel combined with software management (packages), a GUI (display server + desktop environment), and various software tools.

Typically, ROS is designed to work on Ubuntu, which includes the following: a Linux kernel, GNOME desktop environment, the aptitude (apt) package manager.

Ubuntu is a great example of an Open Source project:

  • It is based on another Open Source project: Debian OS, leveraging the Debian community’s work while offering a more user-friendly solution.
  • It aims for profitability through Ubuntu Pro.
  • It is used as a base for other Linux-based OSs, such as Pop!_OS and Zorin.

Visit distrowatch.com to explore the interconnected galaxy of Linux OSs.


The Shell or Terminal

Among the variety of programs running on Linux, we are particularly interested in the terminal emulator, which allows direct manipulation of the system via commands (navigating the directory tree, reading and organizing files, executing scripts or programs, managing system resources such as the network, etc.).

On Ubuntu, the default terminal emulator is gnome-terminal (help.gnome.org), configured with the bash (on Wikipedia) command interpreter.

Commands are interpretable instructions that generally execute programs. The following commands are expected to be known before starting with ROS.

Note: Tab enables autocompletion.

Explore the following commands (i.e., their purpose and usage), then practice using them in your terminal.


The File System

  • ls: List directory elements.
  • cd: Change directory.
  • cat: Display the content of a text file.
  • more: Read a text file page by page.
  • touch: Create a file (if absent).
  • nano: Edit a text file.
  • rm: Permanently remove a file.
  • mkdir: Create a new directory.
  • rmdir: Remove a directory.
  • mv: Move or rename a resource.
  • cp: Copy a file.
  • clear: Clear the shell screen.

Path manipulation:

  • /: Root directory in a Linux system - Example: du /bin/bash (du estimates file space usage).
  • .: Current directory - Example: mkdir ./workspace.
  • ..: Parent directory - Example: cd ../../media.
  • ~: User home directory - Example: cd ~/Documents.
  • CApitAl Letters maTer - Example: cd ~/Documentscd ~/documents.

Mastering Commands

The classical syntax is: command --option -o argument1 - Example: ls -a ~.

Commands exist to help master other commands:

  • man: Command and library manual - Example: man cp.
  • apropos: Search manuals - Example: apropos search.
  • whereis: Locate a resource - Example: whereis python3.
  • alias: Create a custom command - Example: alias listall="ls -a".

Sessions and Environment

A session is an active connection to a system or program.

  • who: List active sessions on a computer.
  • ssh: Open a session on a remote computer using the ssh (Secure Shell) protocol.

An environment is the system configuration in which a program runs. (Wikipedia Sept. 2023).

  • env: List environment variables.
  • $: Access a variable - Example: echo $PATH.
  • export: Create a new variable - Example: export PATH=$PATH:~/bin.
  • ~/.bashrc: User run-command configuration file.

User, Group, and Rules

  • Users are identified and grouped.
  • Users and groups have names and IDs.
  • Resources are owned by users and groups.
  • Access permissions can be configured for resources:
    • r: Read, w: Write, x: Execute/Open.
    • Permissions apply to the user, group, and others.

The ls -l command lists the contents of a directory with ownership and permissions - Example: ls -l /etc.

To list all users: cat /etc/passwd (for groups, cat /etc/group).

Commands:

  • chmod: Change file permissions.
    • Example: chmod +x aFile (add execute permission to aFile).
    • Example: chmod 752 aFile (set permissions in binary style).
  • chown: Change ownership.

Managing Processes

Processes are running instances of programs. Key commands:

  • ps: Lists processes.
    • Example: ps (list local processes started by the current shell).
    • Example: ps -e (list all processes).
  • gedit: launches a graphical text editor. You should use gedit & to get back to the prompt and send the gedit process to the background.
  • top: Interactive process monitoring (Q to quit).
  • kill: Sends signals to processes.
    • Example: kill 19482 (send TERM signal to process 19482).
    • Example: kill -s KILL 19482 (send KILL signal to process 19482).

Processes have attributes like a PID (Process Identifier) and a parent process.


Some Bash Tools and Shortcuts

Bash is one of the shell solutions available on Unix systems.

  • Tab: Auto-complete the command or list possible options.
  • !xx: Re-run the last command starting with xx.
  • Ctrl-R: Search for a command in history.
  • Q: Quit a running program.
  • Ctrl-C: Terminate a running program.
  • ~/.bashrc: User-specific shell configuration file.

For more, see (Wikipedia).