Atlas Robotics
Linux / Ubuntu / JetsonBasic

The terminal and command line: essential skills for robotics

Atlasbot · 20/8/2026 · 10 min read

The terminal and command line: essential skills for robotics
Command prompt structure in Linux terminal

RViz2 has a graphical interface, but most of the actual work with ROS2 — building workspaces, running nodes, viewing topic data, debugging — is done through terminal. Not being familiar with basic command lines makes each step of following the ROS2 instructions a "typing every word correctly but not understanding what you're doing" — this article helps with real understanding, not just copy-pasting.

Read and understand the command prompt (prompt)

Every time you open the terminal, you see a line like user@hostname:~/ros2_ws$ — this is called prompt, indicating 3 information: which user you're logged in with, which machine you're on (hostname — important when SSHing to multiple machines at the same time, it's easy to confuse which machine you're typing commands on), and which directory you're in (~ is the abbreviation for home directory). The $ at the end is a regular user; If you see a # sign, it means you are root — be more careful because any incorrectly typed command has the power to destroy the system.

Basic file movement and manipulation commands

CommandFunctionFor example
pwdPrint current directory (print working directory)pwd → /home/atlas/ros2_ws
lsList files/foldersls -la (show hidden files, detailed format)
cdChange directorycd ros2_ws/src, cd .. (go back 1 level), cd ~ (go home)
mkdirCreate a new foldermkdir -p src/my_package (-p create a parent folder if it doesn't already exist)
cpCopy files/folderscp -r folder1 folder2 (-r to copy the entire folder)
mvMove or renamemv old_name.py new_name.py
rmDelete files/foldersrm -rf build/ (-r recursive, -f does not ask for confirmation — use with care)

View file content quickly without an editor

$ cat package.xml        # Print the entire content to the screen
$ less CMakeLists.txt    # view each page, scroll with arrow keys, exit with q
$ nano launch.py         # Edit files directly in the terminal

Pipe and redirect — chain commands together

The real power of the terminal lies in its ability to combine many simple commands into one complex operation, instead of having one giant command that does everything.

# | (pipe) passes the output of the previous command as input to the next command
$ ros2 topic list | grep scan
/scan

# > write output to file (overwrite), >> append to the end of the file
$ ros2 topic echo /scan > scan_data.txt

# Combine multiple pipes: count the number of running nodes with the word "camera"
$ ros2 node list | grep camera | wc -l
2

grep (find lines containing keywords) is the command used most often with | when doing ROS2 - the list of topics/node/services in a real robot system can be up to dozens of lines. grep helps to quickly filter what you need to find instead of reading it by eye.

Tips for using terminal more effectively

  • Tab to autocomplete (autocomplete) — type the first few characters of the file/command name and then press Tab, the terminal will automatically complete the rest if there are no duplicates — reduce incorrect typing of long names (eg, long ROS2 package name).
  • Up/Down arrow — review previously typed commands, no need to type from the beginning.
  • Ctrl+R — searches backwards in the command history, typing a few characters to find the previously typed long command.
  • Ctrl+C — stop the running program immediately (eg: stop the ROS2 node that is spin indefinitely).
  • !! — rerun the command you just typed, useful when forgetting sudo: type sudo !! to rerun the previous command with sudo permissions.

Technical details

Formulas

Every finished terminal command returns an exit code — the $? variable stores this value immediately after the command finishes running, following a fixed convention:

Exit code = 0 → command successful
Exit code ≠ 0 → command failed (specific value depends on the program's meaning)

For example: check immediately after running
$ colcon build --packages-select my_pkg
$ echo $?
0 ← build successful

Combine && (only continue if the previous command exit code = 0) and || (run only if fails):
$ colcon build && ros2 run my_pkg my_node

The last command line illustrates a very common pattern: only test node if the build is successful, avoid running the old binary by mistake when the build just reports an error without paying attention.

Parameters

A few more useful keyboard shortcuts in addition to the tips mentioned above:

ShortcutsEffects
Ctrl+A / Ctrl+EJump to the beginning / end of the command line you are typing
Ctrl+LClear the terminal screen (equivalent to command clear)
Ctrl+ZSuspend the running program and return it to the background
fg / bgBring the suspended program back to running in the foreground/background

Practical applications

When SSH into the robot to run a long process (eg: ros2 launch the entire system), losing the SSH connection midway (the robot WiFi network is unstable) often causes that process to stop — tools tmux or screen solve this problem correctly: create a "virtual" terminal session that runs independently of the SSH connection, disconnect and then SSH again can still "attach" (attach) back to the same session and see that the process is still running continuously — a skill that is almost required when operating a robot over an absolutely unstable wireless connection.

Practical example: typical terminal process when building ROS2

$ cd ~/ros2_ws                          # go to workspace
$ colcon build --packages-select my_pkg # build a specific package
$ source install/setup.bash             # Reload the environment after build
$ ros2 run my_pkg my_node               # Test run the newly built node

This is a cycle that repeats itself dozens of times a day when developing ROS2 — memorizing these 4 steps is more important than remembering hundreds of other terminal commands.

Common mistakes

  • bash: colcon: command not found — colcon or source /opt/ros/humble/setup.bash is not installed for the current terminal session (ROS2 environment variable is not automatically available, must be reloaded for each new terminal unless ~/.bashrc is added).
  • Build completed but running ros2 run said package could not be found — forgot source install/setup.bash after building, terminal doesn't know where the newly built package is.
  • Mistyped rm -rf with wrong path — there is no "recycle bin" to restore in the terminal, always double check the path before Entering, especially when copying commands from elsewhere.
  • Terminal "freezes" after running a command — maybe the program is running in the background waiting for input or running indefinitely (eg: ros2 topic echo) — use Ctrl+C to stop, not closing the terminal window.

Conclusion

The Terminal isn't as intimidating as it might seem at first glance — most of your day-to-day work with ROS2 revolves around 10 or so basic commands combined with pipe/redirect. The next article in the section is about SSH — how to use this terminal to control the robot remotely, without needing to plug a screen into the robot.

Get new articles and lessons by email

When a new technical article or course module is published, Atlas Robotics sends you a short email. No spam.

Unsubscribe any time with the link in each email. See our Privacy policy.

The terminal and command line: essential skills for robotics — Atlas Robotics