🐧 Module 0.4 Linux Command Line 3 Parts · 24 Topics

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.

📝Part 1 — Fundamentals
📁Part 2 — Navigation & Files
🔎Part 3 — View, Search & Disk
📄  Part 1 — Linux Fundamentals
1Fundamentals

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 VS Code · Chrome · Git requests Operating System manages resources · controls access Hardware (CPU · RAM · Storage)

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.

🔌
Embedded Example
Connecting an ESP32 causes Linux to detect the board, load the driver, and create the device file /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.
2Fundamentals

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.

CommandPurpose
catDisplay file contents
grepSearch for text patterns
sortSort data lines
wcCount 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.

/dev/ttyUSB0 ← represents the ESP32 hardware
  • Linux follows Unix principles closely.
  • Small commands can be combined using pipes (|).
  • Hardware devices are represented as files in /dev/.
3Fundamentals

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.

Applications (GCC, Git, PlatformIO, picocom) Linux Kernel Hardware

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.
4Fundamentals

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.

Applications Desktop Environment Shell (Bash) GNU Utilities Libraries Linux Kernel Hardware

A Linux distribution = Kernel + everything above it. Ubuntu, Debian, and Fedora are distributions.

KernelDistribution
What it isCore OS componentComplete OS
IncludesCPU, memory, device managementKernel + shell + tools + apps
ExamplesLinux 6.xUbuntu, Debian, Fedora
  • Kernel = the core engine.
  • Distribution = the complete, ready-to-use operating system.
  • Ubuntu is the most common distribution for embedded development.
5Fundamentals

Linux File System

The Linux file system organizes all files and directories in a single tree structure starting from the root directory /.

/ ├── home ← User files ├── etc ← Configuration files ├── dev ← Device files ├── usr ← Applications ├── var ← Logs ├── boot ← Boot files ├── proc ← Process info ├── sys ← Kernel info └── tmp ← Temporary files
DirectoryPurpose
/Root — the top of the entire tree
/homeUser personal files (e.g., /home/satwik/)
/etcSystem-wide configuration files
/devDevice files (serial ports, USB, disks)
/usrInstalled applications and libraries
/varVariable data — logs, caches, databases
/bootBootloader and kernel images
/tmpTemporary files (cleared on reboot)
🔌
Embedded Example
Serial devices appear in the file system:
/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.
6Fundamentals

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.

/home/satwik/Documents/report.pdf

Relative Path

Starts from the current directory — a shorter address that only works from your current location.

Projects/Linux

Special Symbols

SymbolMeaningExample
/Root directory/home/satwik
~Your home directory~/Projects
.Current directory./main.c
..Parent directorycd .. → 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.
📁  Part 2 — Navigation & File Management
CommandPurpose
pwdShow current directory
lsList files and folders
cdChange directory
pwdPrint Working Directory — show where you are

Displays the Current Working Directory (CWD). Linux always tracks your current location. Most commands work relative to this location.

Syntax

bash
pwd

Example

bash
pwd
# Output: /home/satwik/Projects
🏭
Embedded Example
cd ~/zephyrproject && pwd — navigate to the Zephyr workspace and confirm you're inside it before running any build commands.
💡
Remember
pwd only shows your location. It never changes it. Use it to verify you're in the correct directory before deleting or overwriting files.
lsList files and directories

Lists the files and directories inside a directory.

bash
ls

Useful Options

bash
ls -l      # detailed view: permissions, owner, size, date
ls -a      # show hidden files (starting with .)
ls -la     # detailed view + hidden files — most commonly used

Understanding ls -l Output

-rw-r--r-- 1 satwik satwik 1234 Jun 1 main.c drwxr-xr-x 2 satwik satwik 4096 Jun 1 Projects/ │ permissions │ owner │ size │ date │ name
🏭
Embedded Example
cd ~/Projects/ESP32 && ls — verify which source files exist before starting to edit.
💡
Remember
ls shows directory contents but never changes your location. Hidden files (like .git/, .bashrc) only appear with -a.
cdChange Directory

Changes the current working directory. After using cd, all relative commands operate from the new location.

bash
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 directory
🏭
Embedded Example
cd ~/Projects/STM32 — navigate directly to your STM32 project using the ~ shortcut for your home directory.
CommandPurpose
mkdirCreate directories
rmdirRemove empty directories
touchCreate empty files
cpCopy files or directories
mvMove or rename
rmDelete files or directories
mkdirMake Directory

Creates a new directory.

bash
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.

🏭
Embedded Example
mkdir Zephyr_Project — create a new project folder before initializing it with West.
touchCreate Empty File / Update Timestamp

Creates an empty file. If the file already exists, it updates the file's last-modified timestamp.

bash
touch main.c                  # create one file
touch main.c uart.c gpio.c    # create multiple files at once

rmdir — Remove Empty Directory

bash
rmdir Test    # removes empty directory only
⚠️
Remember
rmdir fails if the directory contains any files. Use rm -r to remove a directory and all its contents.
cpCopy files or directories

Creates a duplicate of a file or directory. The original remains unchanged.

bash
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)
🏭
Embedded Example
cp -r Firmware Firmware_Backup — make a safety copy of working firmware before making experimental changes.
mvMove or Rename files and directories

Moves a file to a different location OR renames it. Unlike cp, mv removes the original from its starting location.

bash
mv main.c blink.c         # rename a file
mv blink.c Source/        # move into a directory
mv OldProject NewProject  # rename a directory
💡
Remember
mv does not copy — it changes the file's name or location. The original no longer exists at the source path.
rmRemove files and directories permanently

Deletes files and directories. There is no recycle bin — deleted files are gone permanently.

bash
rm notes.txt       # delete a file
rm -r Project      # delete directory and all contents (-r recursive)
rm -rf Project     # force delete without confirmation prompts
🏭
Embedded Example
rm -r build — removes the build directory to force a clean compilation from scratch. Useful when build artifacts are stale or corrupt.
⚠️
Remember
rm permanently deletes files. They are not moved to a Trash folder. Double-check your path before pressing Enter.
🔎  Part 3 — Viewing, Searching & Disk Usage
CommandPurpose
catDisplay entire file contents
lessRead large files page by page
headShow the beginning of a file
tailShow the end of a file
catDisplay complete file contents

cat prints the entire contents of a file directly to the terminal. Best for small files.

bash
cat README.md               # show one file
cat file1.txt file2.txt     # show multiple files in sequence
🏭
Embedded Example
cat prj.conf — quickly view the Zephyr project configuration without opening an editor.
💡
Remember
Avoid using cat for very large files — everything prints at once and scrolls off the screen. Use less instead.
lessRead files page by page

Opens a file in a scrollable viewer. Essential for reading long log files and build outputs.

bash
less build.log

Navigation Keys Inside less

KeyAction
↑ / ↓Scroll up / down one line
SpaceScroll down one page
bScroll up one page
/textSearch for text forward
qQuit
🏭
Embedded Example
less firmware.log — comfortably navigate long firmware build logs without everything scrolling by at once.
headShow the beginning of a file

Displays the first 10 lines of a file by default. Use -n to specify a different count.

bash
head main.c           # show first 10 lines
head -n 20 main.c     # show first 20 lines
🏭
Embedded Example
head main.c — quickly inspect the license header or includes at the top of a source file.
tailShow the end of a 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.

bash
tail build.log           # last 10 lines
tail -n 50 build.log     # last 50 lines
tail -f firmware.log     # follow live — stop with Ctrl+C
🏭
Embedded Example
tail -f firmware.log — watch firmware UART output in real time as your embedded device runs.
💡
Remember
tail -f is one of the most commonly used embedded debugging tools — it streams log output continuously. Press Ctrl+C to stop.
CommandPurpose
findFind files and directories
grepSearch text inside files
rgFast recursive text search (Ripgrep)
locateFind files using index database
findSearch for files and directories

find searches for files and directories based on name, type, or other attributes.

bash
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 files

The . means start searching from the current directory. You can replace it with any path.

🏭
Embedded Example
find . -name "*.conf" — locate all Zephyr prj.conf and KConfig files across a large project.
grepSearch for text inside files

grep searches for a pattern inside file contents. Unlike find, which finds files, grep finds text inside files.

bash
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 directory

Key Flags

FlagEffect
-rSearch recursively through all subdirectories
-nShow line numbers in results
-iCase-insensitive search
-lShow only filenames, not matching lines
🏭
Embedded Example
grep -rn "ERROR" logs/ — find all error messages across all log files, with exact line numbers for fast debugging.
rgRipgrep — faster alternative to grep

Ripgrep (rg) is a modern, extremely fast search tool designed for source code. It searches recursively by default and respects .gitignore.

bash
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 project
🏭
Embedded Example
rg "SystemClock_Config" — instantly find where the STM32 system clock is configured across an entire CubeIDE project.
💡
Remember
rg searches recursively by default — no need for -r. It also automatically skips build/ and .git/ directories (via .gitignore), so results are always relevant.
locateFind files using a pre-built database

locate is extremely fast because it searches a pre-built database rather than scanning the filesystem in real time.

bash
locate main.c        # find main.c anywhere on the system
sudo updatedb        # update the database (needed for recent files)
⚠️
Remember
locate may not find recently created files until you run sudo updatedb. For newly created files, use find instead.
CommandPurpose
duSize of files and directories
dfFree space on the entire disk
duDisk Usage — size of files and folders

Shows how much disk space files and directories consume.

bash
du -sh .                    # size of current directory
du -sh *                    # size of every item here
du -sh ~/zephyrproject      # size of Zephyr workspace

The -s flag gives a summary total (not every subfolder). The -h flag shows human-readable sizes (MB, GB).

🏭
Embedded Example
du -sh ~/zephyrproject — check how much disk space your Zephyr SDK and workspace consume before installing another SDK.
dfDisk Free — available space on the entire disk

Shows total, used, and available space for each mounted filesystem.

bash
df -h    # human-readable disk space for all filesystems

Example Output

Filesystem Size Used Avail Use% Mounted on /dev/sda1 512G 280G 232G 55% /
ColumnMeaning
SizeTotal storage on the partition
UsedSpace currently in use
AvailFree space remaining
Use%Percentage of total space used
🏭
Embedded Example
Run 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 vs df
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.
🚀 Complete Command Reference
  • 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 -f for 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