Development & Scripting – Linux Teaching Plan

Duration: 2 hours (≈ 10 min per command). Audience: Developers who need to master the basic tooling used on a Linux workstation or build server.

Learning Objectives

  1. Use version control (Git) to clone, commit, and push changes.
  2. Write and run Bash scripts to automate tasks.
  3. Install and manage packages with pip and npm.
  4. Compile C/C++ code with gcc, make, and cmake.
  5. Manipulate text streams with sed and awk.
  6. Edit code interactively with vim and use tmux for session management.
  7. Search and filter files using grep and find.
  8. Interact with web services via curl and parse JSON with jq.
  9. Write a simple static site generator as a final project.

Schedule & Topics

  1. Introduction to the toolchain (5 min)
  2. Git basics (10 min)
  3. Bash scripting (10 min)
  4. Python & pip (10 min)
  5. Node.js & npm (10 min)
  6. gcc & make (10 min)
  7. cmake (10 min)
  8. sed & awk (10 min)
  9. vim & tmux (10 min)
  10. grep & find (10 min)
  11. curl & jq (10 min)
  12. Mini‑project: static‑site‑generator (15 min)
  13. Assessment & Wrap‑up (10 min)

Command Topics & Hands‑On Exercises

1. git – Version Control

git init myrepo
cd myrepo
echo "Hello, Git!" > hello.txt
git add hello.txt
git commit -m "Initial commit"
git remote add origin https://github.com/you/myrepo.git
git push -u origin master

2. bash – Script Automation

#!/usr/bin/env bash
# backup.sh – simple backup of a directory
SRC="/home/you/project"
DEST="/tmp/project-backup-$(date +%F).tar.gz"
tar -czf "$DEST" "$SRC"
echo "Backup created at $DEST"

3. python & pip – Package Management

python3 -m venv venv
source venv/bin/activate
pip install requests
python -c "import requests, sys; print(requests.get('https://api.github.com').status_code)"

4. node & npm – JavaScript Runtime

npm init -y
npm install express
node -e "const express=require('express');const app=express();app.get('/',(req,res)=>res.send('Hello!'));app.listen(3000,()=>console.log('Listening 3000'))"

5. gcc & make – C Build Tools

# hello.c
#include <stdio.h>
int main(){ printf("Hello from C!\n"); return 0; }

# Makefile
CC=gcc
CFLAGS=-Wall -O2
TARGET=hello

all: $(TARGET)

$(TARGET): hello.c
    $(CC) $(CFLAGS) -o $(TARGET) hello.c

clean:
    rm -f $(TARGET)

6. cmake – Modern Build System

# CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
project(Hello C)
add_executable(hello hello.c)

7. sed – Stream Editor

# Replace "foo" with "bar" in file.txt
sed -i 's/foo/bar/g' file.txt

# Show only lines containing "error"
sed -n '/error/p' logfile.txt

8. awk – Pattern Scanning

# Sum the 3rd column in a CSV
awk -F',' '{sum+=$3} END{print sum}' data.csv

# Print the 1st and 3rd fields of lines that contain "PASS"
awk '$0 ~ /PASS/ {print $1, $3}' results.txt

9. vim – Powerful Text Editor

# Basic vim workflow
vim file.txt   # enter normal mode
i              # insert mode
...edit...
Esc            # back to normal
:wq            # write & quit

# Example of searching
/keyword
n  # next match

10. tmux – Terminal Multiplexer

# Start a new session
tmux new -s dev

# Split horizontally
Ctrl+b %
# Split vertically
Ctrl+b "

# Switch panes
Ctrl+b o

# Detach
Ctrl+b d

# List sessions
tmux ls
# Attach to session
tmux attach -t dev

11. grep – Pattern Matching

# Find all files containing "TODO"
grep -rl "TODO" .

# Show only the matching part
grep -o "error:.*" syslog.log

# Recursive search case‑insensitive
grep -ri "fatal" .

12. find – File Discovery

# Find all .log files modified in last 7 days
find . -name "*.log" -mtime -7

# Delete all .tmp files
find /tmp -type f -name "*.tmp" -delete

# Execute a command on each file
find . -name "*.py" -exec pyflakes {} +

13. curl – HTTP Client

# GET request
curl https://api.github.com/repos/torvalds/linux

# POST with JSON payload
curl -X POST https://httpbin.org/post \
     -H "Content-Type: application/json" \
     -d '{"name":"dev","role":"engineer"}'

14. jq – JSON Processor

# Extract all tag names from GitHub releases
curl https://api.github.com/repos/nodejs/node/releases \
  | jq '.[].tag_name'

# Pretty‑print and filter
cat data.json | jq '.[] | select(.active==true) | .name'

Mini‑Project: Static Site Generator (Bash)

Students will combine at least 5 of the commands above to build a tiny static site generator that:

  1. Creates a site directory.
  2. Copies a template.html into site/index.html.
  3. Accepts markdown files from posts/, converts them to HTML using pandoc (installed via apt or brew).
  4. Uses sed to replace a placeholder (e.g., {{content}}) with the rendered HTML.
  5. Writes a build.sh script that orchestrates all steps and can be run with ./build.sh.
  6. Shows output in a git commit and pushes the final site/ to a GitHub Pages repo.

Deliverables: build.sh, README.md explaining the pipeline, and a live site served via python3 -m http.server.

Assessment & Wrap‑up

  1. Quiz (5 questions) – 3‑choice multiple choice covering Git, make, grep, sed, and curl.
  2. Hands‑on Task – Students run a script that uses git, grep, and awk to produce a report of all TODO comments in the repo.
  3. Project Review – In pairs, students present their static site generator, explain their choice of commands, and demonstrate a successful build.

Score sheet (out of 30 points):

TaskPoints
Git clone/commit/push 5
Bash script (backup.sh) 5
Python pip env 5
gcc/make build 5
sed/awk usage 5
Mini‑project 5

Resources