Why Linux Matters: Practice Exercises
These exercises reinforce the concepts from Chapter 3. They range from research and exploration tasks to hands-on shell practice.
Exercise 1 — Research: Linux in Your Favourite CI/CD Tool
Difficulty: ⭐ Easy
Look up the documentation for one of these CI/CD platforms and answer the questions below:
- GitHub Actions
- GitLab CI/CD
- Jenkins
- CircleCI
Tasks:
- Find what the default runner/agent operating system is for jobs
- Find the command to print the OS version in a CI job (
uname -aorcat /etc/os-release) - Write a minimal CI configuration file (
.github/workflows/main.ymlor.gitlab-ci.yml) that:- Runs on the platform’s default Linux runner
- Prints
uname -a - Prints the current user with
whoami
💡 Show Answer (GitHub Actions Example)
# .github/workflows/linux-check.yml
name: Linux Check
on: [push]
jobs:
check:
runs-on: ubuntu-22.04 # Ubuntu Linux — the default GitHub Actions runner
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Print OS info
run: uname -a
# Expected output:
# Linux runner-name 5.15.0-1052-aws #58~20.04.1-Ubuntu SMP Mon May 20 ...
- name: Print current user
run: whoami
# Expected output:
# runner
GitLab CI equivalent:
# .gitlab-ci.yml
linux-check:
image: ubuntu:22.04
script:
- uname -a
- whoami
Key takeaway: GitHub Actions defaults to ubuntu-22.04. GitLab CI uses a Docker image (which is Linux). Both environments are Linux.
Exercise 2 — Cron Scheduling
Difficulty: ⭐⭐ Medium
Write the cron expressions for the following schedules:
- Every day at midnight (00:00)
- Every Monday at 8:00 AM
- Every 15 minutes
- On the 1st day of every month at 6:00 AM
- At 23:59 on December 31st every year
Then, write a simple shell script that:
- Appends the current date and time to
/tmp/cron-test.log - Schedule it to run every minute using crontab
💡 Show Answer
Cron expressions:
# 1. Every day at midnight
0 0 * * *
# 2. Every Monday at 8:00 AM
0 8 * * 1
# 3. Every 15 minutes
*/15 * * * *
# 4. On the 1st of every month at 6:00 AM
0 6 1 * *
# 5. At 23:59 on December 31st every year
59 23 31 12 *
Shell script:
#!/usr/bin/env bash
# /home/ubuntu/scripts/cron-test.sh
echo "$(date '+%Y-%m-%d %H:%M:%S') - cron ran successfully" >> /tmp/cron-test.log
# Make executable
chmod +x /home/ubuntu/scripts/cron-test.sh
# Add to crontab
crontab -e
# Add this line:
* * * * * /home/ubuntu/scripts/cron-test.sh
# Verify after 2 minutes
cat /tmp/cron-test.log
# 2025-04-01 10:01:01 - cron ran successfully
# 2025-04-01 10:02:01 - cron ran successfully
# Remove the cron job when done
crontab -e
# Delete the line you added
Exercise 3 — Package Manager Exploration
Difficulty: ⭐⭐ Medium
Using your system’s package manager (apt, dnf, or brew):
- Search for the
htoppackage and find its description - Install
htopif it isn’t already installed - Run
htop— pressqto quit - Find out which package provides the
digcommand - Install the package that provides
digand run:dig google.com +short
💡 Show Answer (Ubuntu/Debian)
# 1. Search for htop
apt search htop
# htop/jammy 3.0.5-7build2 amd64
# interactive processes viewer
# 2. Install htop
sudo apt install htop
# 3. Run htop
htop
# Press q to quit
# 4. Find which package provides 'dig'
apt-file search bin/dig
# Or use:
apt search dig | grep -i "dns"
# dnsutils/jammy ... Clients provided with BIND ...
# 5. Install dnsutils and run dig
sudo apt install dnsutils
dig google.com +short
# 142.250.182.46
# (IP address of google.com — yours may differ)
On macOS with Homebrew:
# 1. Search
brew search htop
# ==> Formulae: htop
# 2. Install
brew install htop
# 4. dig is included with macOS — but for the latest:
brew install bind
dig google.com +short
Exercise 4 — Linux vs Windows: Cost Calculator
Difficulty: ⭐⭐ Medium
Calculate the annual cost difference between Linux and Windows Server for a fleet of 50 EC2 t3.large instances running 24/7.
Use these approximate on-demand prices (us-east-1):
- Linux
t3.large: $0.0832/hour - Windows
t3.large: $0.1392/hour
Answer these questions:
- Monthly cost for 50 Linux instances
- Monthly cost for 50 Windows instances
- Annual savings by choosing Linux
- What else, beyond EC2 costs, would you save by choosing Linux?
💡 Show Answer
# Calculate with bash
python3 - <<'EOF'
linux_hourly = 0.0832
windows_hourly = 0.1392
instances = 50
hours_per_month = 730 # 365 days × 24 hours / 12
linux_monthly = linux_hourly * instances * hours_per_month
windows_monthly = windows_hourly * instances * hours_per_month
linux_annual = linux_monthly * 12
windows_annual = windows_monthly * 12
savings_annual = windows_annual - linux_annual
print(f"Linux monthly: ${linux_monthly:,.2f}")
print(f"Windows monthly: ${windows_monthly:,.2f}")
print(f"Linux annual: ${linux_annual:,.2f}")
print(f"Windows annual: ${windows_annual:,.2f}")
print(f"Annual savings: ${savings_annual:,.2f}")
EOF
Linux monthly: $3,036.80
Windows monthly: $5,080.80
Linux annual: $36,441.60
Windows annual: $60,969.60
Annual savings: $24,528.00
Additional savings with Linux (beyond EC2):
- No Windows Server CAL (Client Access Licences)
- No SQL Server licences (use PostgreSQL instead)
- No IIS licences (use nginx/Apache, both free)
- No Systems Centre / SCCM costs (use Ansible)
- Lower support costs (larger community, more free resources)
Total additional savings could easily exceed $50,000–$100,000/year for 50 servers when licensing is factored in.
Exercise 5 — Open Source Tool Discovery
Difficulty: ⭐⭐⭐ Challenging
Discover and evaluate three open source Linux tools you have not used before:
Instructions:
- Go to https://github.com/agarrharr/awesome-cli-apps or search GitHub for “awesome linux tools”
- Pick three tools you haven’t used
- For each tool:
- Find its GitHub repository
- Note: stars, last commit date, licence, and short description
- Install it using your package manager (or build from source)
- Run it and note one useful command
- Write a brief comparison: which tool would you use in a real DevOps workflow and why?
💡 Show Answer (Example Selection)
Tool 1: bat — a better cat
# GitHub: https://github.com/sharkdp/bat
# Stars: 47k+ | Active | MIT Licence
# Description: cat clone with syntax highlighting and line numbers
sudo apt install bat # Ubuntu 22.04+
# or: sudo apt install bat-cat # on older Ubuntu
# Usage
bat /etc/nginx/nginx.conf # Shows config with syntax highlighting + line numbers
bat README.md # Markdown rendered in terminal
bat --plain myfile.txt # No decorations (like regular cat)
Tool 2: ripgrep (rg) — a faster grep
# GitHub: https://github.com/BurntSushi/ripgrep
# Stars: 47k+ | Active | MIT Licence
# Description: fast grep that respects .gitignore
sudo apt install ripgrep
# Usage
rg "TODO" src/ # Search for TODO in src/ directory recursively
rg -i "error" /var/log/ # Case-insensitive search in logs
rg --type py "def main" # Search only Python files
Tool 3: fd — a faster find
# GitHub: https://github.com/sharkdp/fd
# Stars: 33k+ | Active | MIT & Apache Licence
# Description: simple, fast alternative to find
sudo apt install fd-find
# On Ubuntu, the binary is 'fdfind', alias it:
alias fd=fdfind
# Usage
fd ".log" /var/log/ # Find all .log files
fd -t f -x wc -l # Find files and run wc -l on each
fd --changed-within 1d # Files changed in the last day
Which to use in DevOps:
bat→ replacecatin day-to-day config file reviewrg→ replacegrep -rwhen searching codebases or log directoriesfd→ replacefindfor file discovery in large repositories
All three are faster and more ergonomic than their standard equivalents.
Chapter Summary
After completing these exercises you should be able to:
- ✅ Configure a CI/CD job on a Linux runner
- ✅ Write and schedule cron jobs for automation
- ✅ Use your distro’s package manager to search, install, and manage tools
- ✅ Calculate and understand the cost difference between Linux and Windows cloud instances
- ✅ Discover, evaluate, and install open source Linux tools
| ← Back to Open Source Ecosystem | Next Chapter → Setup & Environment |