Linux Command Line
for Embedded Systems
From OS fundamentals to filesystem navigation, file management, viewing, searching, and disk usage — the complete Linux CLI toolkit for embedded developers.
Operating System (OS)
An Operating System (OS) is the most important software on a computer. It acts as a bridge between the hardware and the applications.
When you use VS Code, Chrome, or Git, they do not communicate directly with the CPU, RAM, or SSD. Instead, they send requests to the operating system, which manages hardware and returns the required results.
Applications request services from the OS. The OS controls hardware access, never allowing apps to communicate directly with hardware.
Why Do We Need an Operating System?
Without an OS, every application would need to know how every hardware device works. The operating system provides a common interface between applications and hardware — so developers write to a standard API, not to raw hardware registers.
Main Responsibilities
CPU Management
Schedules processes and distributes CPU time.
Memory Management
Allocates and protects RAM per process.
File Management
Organizes and controls access to storage.
Device Management
Loads drivers and controls hardware devices.
/dev/ttyUSB0. Tools like picocom communicate with the board through this virtual file.- The operating system connects software and hardware.
- It manages all system resources centrally.
- Linux, Windows, and macOS are all operating systems.
Unix
Unix is one of the earliest modern operating systems. Most ideas introduced by Unix are still used in Linux today.
Unix Philosophy
Do one thing, and do it well.
Small commands are designed to do exactly one task correctly, and they can be combined together using pipes to solve complex problems.
| Command | Purpose |
|---|---|
cat | Display file contents |
grep | Search for text patterns |
sort | Sort data lines |
wc | Count lines and words |
Everything is a File
Linux inherited this core Unix idea. In Linux, everything is represented as a file — regular files, directories, hard disks, serial ports, and USB devices all appear in the filesystem.
- Linux follows Unix principles closely.
- Small commands can be combined using pipes (
|). - Hardware devices are represented as files in
/dev/.
Linux
Linux is a free and open-source kernel. The kernel manages hardware resources — CPU, memory, storage, and devices. A complete operating system is built by combining the Linux kernel with other software.
The kernel sits between applications and hardware, handling all resource management.
Why Embedded Engineers Use Linux
Linux is the primary development environment for embedded systems because it natively runs the tools the industry depends on:
GCC / CMake
Cross-compilation toolchains for ARM, RISC-V, and more.
Git & GitHub
Version control for firmware source code.
PlatformIO
Multi-board embedded IDE and build system.
picocom / OpenOCD
Serial monitor and hardware debugger tools.
- Linux is a kernel — the core of the operating system.
- It manages all hardware resources.
- It is the standard environment for embedded development worldwide.
Linux Kernel vs Linux Distribution
Linux Kernel — The Core
The kernel manages: CPU scheduling, memory allocation, device drivers, processes, and file systems. It is the lowest level of software directly above hardware.
Linux Distribution — The Complete System
A distribution bundles the kernel with everything a user needs: GNU tools, Bash shell, libraries, a package manager, and applications.
A Linux distribution = Kernel + everything above it. Ubuntu, Debian, and Fedora are distributions.
| Kernel | Distribution | |
|---|---|---|
| What it is | Core OS component | Complete OS |
| Includes | CPU, memory, device management | Kernel + shell + tools + apps |
| Examples | Linux 6.x | Ubuntu, Debian, Fedora |
- Kernel = the core engine.
- Distribution = the complete, ready-to-use operating system.
- Ubuntu is the most common distribution for embedded development.
Linux File System
The Linux file system organizes all files and directories in a single tree structure starting from the root directory /.
| Directory | Purpose |
|---|---|
/ | Root — the top of the entire tree |
/home | User personal files (e.g., /home/satwik/) |
/etc | System-wide configuration files |
/dev | Device files (serial ports, USB, disks) |
/usr | Installed applications and libraries |
/var | Variable data — logs, caches, databases |
/boot | Bootloader and kernel images |
/tmp | Temporary files (cleared on reboot) |
/dev/ttyUSB0 → ESP32 connected via USB/dev/ttyACM0 → STM32 connected via USB- Linux uses a single unified tree structure starting at
/. - Every device is accessible as a file under
/dev/. - There are no drive letters (C:, D:) — only directory paths.
Linux Paths
A path is the address of a file or directory in the filesystem.
Absolute Path
Starts from the root directory / — the full address from the very top of the tree.
Relative Path
Starts from the current directory — a shorter address that only works from your current location.
Special Symbols
| Symbol | Meaning | Example |
|---|---|---|
/ | Root directory | /home/satwik |
~ | Your home directory | ~/Projects |
. | Current directory | ./main.c |
.. | Parent directory | cd .. → go up one level |
- Absolute paths start with
/and always work from anywhere. - Relative paths start from your current directory.
~,., and..are critical shortcuts used constantly.
| Command | Purpose |
|---|---|
pwd | Show current directory |
ls | List files and folders |
cd | Change directory |
Displays the Current Working Directory (CWD). Linux always tracks your current location. Most commands work relative to this location.
Syntax
pwdExample
pwd
# Output: /home/satwik/Projectscd ~/zephyrproject && pwd — navigate to the Zephyr workspace and confirm you're inside it before running any build commands.pwd only shows your location. It never changes it. Use it to verify you're in the correct directory before deleting or overwriting files.Lists the files and directories inside a directory.
lsUseful Options
ls -l # detailed view: permissions, owner, size, date
ls -a # show hidden files (starting with .)
ls -la # detailed view + hidden files — most commonly usedUnderstanding ls -l Output
cd ~/Projects/ESP32 && ls — verify which source files exist before starting to edit.ls shows directory contents but never changes your location. Hidden files (like .git/, .bashrc) only appear with -a.Changes the current working directory. After using cd, all relative commands operate from the new location.
cd Projects # move into a directory (relative)
cd /home/satwik/Documents # absolute path
cd # go to home directory
cd ~ # go to home directory (same as above)
cd .. # go up one level (parent directory)
cd - # return to the previous directorycd ~/Projects/STM32 — navigate directly to your STM32 project using the ~ shortcut for your home directory.| Command | Purpose |
|---|---|
mkdir | Create directories |
rmdir | Remove empty directories |
touch | Create empty files |
cp | Copy files or directories |
mv | Move or rename |
rm | Delete files or directories |
Creates a new directory.
mkdir STM32_Project # create one directory
mkdir -p Projects/ESP32/Blink # create nested dirs (-p = parents)The -p flag creates all missing parent directories automatically — no error if they already exist.
mkdir Zephyr_Project — create a new project folder before initializing it with West.Creates an empty file. If the file already exists, it updates the file's last-modified timestamp.
touch main.c # create one file
touch main.c uart.c gpio.c # create multiple files at oncermdir — Remove Empty Directory
rmdir Test # removes empty directory onlyrmdir fails if the directory contains any files. Use rm -r to remove a directory and all its contents.Creates a duplicate of a file or directory. The original remains unchanged.
cp main.c backup.c # copy file with new name
cp main.c Backup/ # copy file into directory
cp -r Project Backup # copy entire directory (-r = recursive)cp -r Firmware Firmware_Backup — make a safety copy of working firmware before making experimental changes.Moves a file to a different location OR renames it. Unlike cp, mv removes the original from its starting location.
mv main.c blink.c # rename a file
mv blink.c Source/ # move into a directory
mv OldProject NewProject # rename a directorymv does not copy — it changes the file's name or location. The original no longer exists at the source path.Deletes files and directories. There is no recycle bin — deleted files are gone permanently.
rm notes.txt # delete a file
rm -r Project # delete directory and all contents (-r recursive)
rm -rf Project # force delete without confirmation promptsrm -r build — removes the build directory to force a clean compilation from scratch. Useful when build artifacts are stale or corrupt.rm permanently deletes files. They are not moved to a Trash folder. Double-check your path before pressing Enter.| Command | Purpose |
|---|---|
cat | Display entire file contents |
less | Read large files page by page |
head | Show the beginning of a file |
tail | Show the end of a file |
cat prints the entire contents of a file directly to the terminal. Best for small files.
cat README.md # show one file
cat file1.txt file2.txt # show multiple files in sequencecat prj.conf — quickly view the Zephyr project configuration without opening an editor.cat for very large files — everything prints at once and scrolls off the screen. Use less instead.Opens a file in a scrollable viewer. Essential for reading long log files and build outputs.
less build.logNavigation Keys Inside less
| Key | Action |
|---|---|
↑ / ↓ | Scroll up / down one line |
Space | Scroll down one page |
b | Scroll up one page |
/text | Search for text forward |
q | Quit |
less firmware.log — comfortably navigate long firmware build logs without everything scrolling by at once.Displays the first 10 lines of a file by default. Use -n to specify a different count.
head main.c # show first 10 lines
head -n 20 main.c # show first 20 lineshead main.c — quickly inspect the license header or includes at the top of a source file.Displays the last 10 lines of a file. The -f flag follows the file in real time as new lines are added — perfect for live log monitoring.
tail build.log # last 10 lines
tail -n 50 build.log # last 50 lines
tail -f firmware.log # follow live — stop with Ctrl+Ctail -f firmware.log — watch firmware UART output in real time as your embedded device runs.tail -f is one of the most commonly used embedded debugging tools — it streams log output continuously. Press Ctrl+C to stop.| Command | Purpose |
|---|---|
find | Find files and directories |
grep | Search text inside files |
rg | Fast recursive text search (Ripgrep) |
locate | Find files using index database |
find searches for files and directories based on name, type, or other attributes.
find . -name "main.c" # find file named main.c
find . -name "*.c" # find all C source files
find . -type d # find directories only
find . -name "*.conf" # find all config filesThe . means start searching from the current directory. You can replace it with any path.
find . -name "*.conf" — locate all Zephyr prj.conf and KConfig files across a large project.grep searches for a pattern inside file contents. Unlike find, which finds files, grep finds text inside files.
grep "main" main.c # search one file
grep -rn "TODO" . # search all files recursively with line numbers
grep -rn "ERROR" logs/ # find error messages in log directoryKey Flags
| Flag | Effect |
|---|---|
-r | Search recursively through all subdirectories |
-n | Show line numbers in results |
-i | Case-insensitive search |
-l | Show only filenames, not matching lines |
grep -rn "ERROR" logs/ — find all error messages across all log files, with exact line numbers for fast debugging.Ripgrep (rg) is a modern, extremely fast search tool designed for source code. It searches recursively by default and respects .gitignore.
rg "UART_Init" # search all files for UART_Init
rg -n TODO # search with line numbers
rg "SystemClock_Config" # find a function across a large projectrg "SystemClock_Config" — instantly find where the STM32 system clock is configured across an entire CubeIDE project.rg searches recursively by default — no need for -r. It also automatically skips build/ and .git/ directories (via .gitignore), so results are always relevant.locate is extremely fast because it searches a pre-built database rather than scanning the filesystem in real time.
locate main.c # find main.c anywhere on the system
sudo updatedb # update the database (needed for recent files)locate may not find recently created files until you run sudo updatedb. For newly created files, use find instead.| Command | Purpose |
|---|---|
du | Size of files and directories |
df | Free space on the entire disk |
Shows how much disk space files and directories consume.
du -sh . # size of current directory
du -sh * # size of every item here
du -sh ~/zephyrproject # size of Zephyr workspaceThe -s flag gives a summary total (not every subfolder). The -h flag shows human-readable sizes (MB, GB).
du -sh ~/zephyrproject — check how much disk space your Zephyr SDK and workspace consume before installing another SDK.Shows total, used, and available space for each mounted filesystem.
df -h # human-readable disk space for all filesystemsExample Output
| Column | Meaning |
|---|---|
| Size | Total storage on the partition |
| Used | Space currently in use |
| Avail | Free space remaining |
| Use% | Percentage of total space used |
df -h before installing a new SDK (Zephyr, ESP-IDF, nRF Connect). SDKs can consume 10–30 GB. Verify you have enough free space first.du measures how much space a specific folder or file uses. df shows how much free space is left on the entire disk. Use both together.- pwd — print current directory path.
- ls / ls -la — list files including hidden.
- cd — change directory;
cd ~,cd ..,cd -are key shortcuts. - mkdir -p — create nested directories in one command.
- touch — create empty files; rmdir — remove empty directories.
- cp -r — copy directory recursively; mv — move or rename.
- rm -rf — force-delete a directory permanently (no undo).
- cat — display small files; less — scroll through large files.
- head / tail — first or last N lines;
tail -ffor live log streaming. - find — search for files; grep / rg — search inside files.
- du -sh — folder size; df -h — total disk space remaining.
Module 0.4 — Linux Command Line for Embedded Systems · Embedded Systems Foundations