Linux and the Command Line for Data Work
Get comfortable on a Linux shell: navigating files, inspecting large datasets, piping commands, permissions, processes, SSH and cron.
Beginner · about 6 hours · difficulty 2/5
Pipelines run on Linux servers and containers, so the shell is where you debug them. You will tail logs, peek at multi-gigabyte CSVs and SSH into machines long before you touch a fancy UI.
Everyday commands
- Navigation and files:
ls,cd,pwd,cp,mv,rm,mkdir,find. - Looking at data without opening it:
head,tail -f,wc -l,less,cut,sort,uniq -c. - Searching and transforming:
grep,sed,awk, andjqfor JSON. - Pipes and redirection:
cat orders.csv | cut -d, -f3 | sort | uniq -c | sort -nr | headfinds the top cities in seconds.
System basics
- Permissions: read, write, execute for user, group and others;
chmodandchown. - Processes:
ps,toporhtop,kill, background jobs,nohup. - Disk and memory:
df -h,du -sh,free -h. Full disks kill pipelines more often than bad code. - Environment variables for config and secrets, and
.bashrcfor your setup. - SSH with keys, and
scporrsyncfor moving files. - cron for simple schedules, the ancestor of every orchestrator.
Shell scripts
Write small Bash scripts with set -euo pipefail so they fail loudly. Anything longer than about 50 lines usually belongs in Python.
Pitfalls
- Running
rm -rfwith an unset variable in the path. Quote variables and useset -u. - Opening a 5 GB file in a text editor. Use
headandwcfirst. - Windows users: use WSL2 so your environment matches production.
You are ready to move on when you can answer "how many rows, how many distinct values in column 4, and what does the last line look like?" for a large CSV using only the shell.
Key concepts
- Files, directories and paths
- head, tail, wc, less
- grep, sed, awk, cut, sort, uniq
- Pipes and redirection
- Permissions and users
- Processes and resource usage
- SSH, scp and rsync
- cron scheduling
- jq for JSON
- WSL2 on Windows
Mini project
Download a public CSV from data.gov.in. Using only shell commands, report row count, column headers, the top 10 values of one column with counts, and any rows with the wrong number of fields. Save the commands as a Bash script.
Check yourself
A nightly job failed with 'No space left on device'. Which commands would you run to find what filled the disk?
Free resources
- The Missing Semester of Your CS Education (MIT)
- Linux Journey (Linux Journey)
- Linux roadmap (roadmap.sh)
- GNU Bash manual (GNU)