3  Linux Basics

This chapter presents fundamental Linux operations such as directory creation, file generation, and initial data inspection. Mastering these commands provides a solid foundation for the more advanced shell techniques introduced in later chapters.

3.1 Creating and Inspecting Files

set -euo pipefail

# Create folders
mkdir -p data/raw data/processed

# Create a simple CSV file
printf "ticker,date,adj_close\nAAPL,2023-01-02,125.0\nAAPL,2023-01-03,126.5\n" > data/raw/prices.csv

# Count rows in the file
wc -l data/raw/prices.csv

# Preview the first few lines
head -n 3 data/raw/prices.csv

3.2 Explanation

This example demonstrates essential Linux basics used in data workflows:

mkdir -p constructs directories while avoiding errors if they already exist.

printf writes a simple CSV dataset to the data/raw/ folder.

wc -l verifies the number of records, which helps catch missing or duplicated data.

head -n 3 reveals the top rows, confirming formatting and column names.

Together, these commands show how Linux supports quick and transparent file creation and validation in a reproducible workflow.