Bash Basics

Learn through engaging narratives and interactive challenges

8 lessons available

Lessons

1

Waking Up in the Wilderness

The terminal is your window into the file system. pwd β€” shows where you are (Print Working Directory). ls β€” lists files and folders. Add -la for hidden files and details. cd β€” changes directory. cd .. goes up, cd ~ goes home. mkdir β€” creates new directories.

2

Gathering Resources

touch β€” creates empty files. The name comes from the Unix idea of "touching" a file's timestamp, but if the file doesn't exist, it creates one. Like tapping something into existence. echo β€” prints text to the screen. Named because it echoes your words back at you. > β€” the redirect operator. Instead of printing to screen, it pours output into a file. echo "hello" > file.txt creates (or overwrites) file.txt with "hello". cat β€” short for "concatenate" (joining files together), but most people use it to simply display a file's contents on screen. cp β€” copies files: cp source dest. The original stays untouched. mv β€” moves OR renames files: mv old new. Same command, two uses. rm β€” removes files permanently. No trash can, no undo. Gone means gone. Tip: use ; to chain commands on one line β€” echo hi > a.txt; cp a.txt b.txt does both in sequence.

3

Tracking Signs

grep β€” searches for text patterns inside files. Usage: grep "pattern" file.txt. Flags: -i (case-insensitive), -r (recursive through directories), -n (show line numbers). The name stands for Global Regular Expression Print. There's a hacker saying: 'You can't grep dead trees' β€” meaning digital text is searchable, but paper isn't. That's your superpower. find β€” locates files by name, size, or type across directories. Usage: find . -name "*.txt" finds all .txt files from the current directory down.

4

Building a Water Filter

The pipe | is the most powerful concept in bash. It takes the output of one command and feeds it as input to the next. Unlike ; (which just runs commands in sequence), | connects them β€” data flows through. head -n N β€” shows the first N lines. tail -n N β€” shows the last N lines. sort β€” sorts lines alphabetically or numerically (-n). uniq β€” removes adjacent duplicate lines (always sort first). wc -l β€” counts lines.

5

The Cleanup Crew

xargs β€” the bridge between finding things and acting on them. It takes a list from stdin and passes each item as an argument to another command. Example: find . -name "*.tmp" | xargs rm β€” finds all .tmp files and deletes them in one sweep. Without xargs, you'd have to delete them one by one. Power pipeline: cat log.txt | grep "ERROR" | awk "{print $1}" | sort | uniq -c β€” reads a log, filters errors, extracts the first column, sorts, and counts occurrences.

6

Field Surgery on Text

sed (Stream Editor) β€” performs text substitution on a stream. sed "s/old/new/" replaces the first occurrence per line. Add g for all: sed "s/old/new/g". awk β€” processes columnar data. It splits each line into fields ($1, $2, etc.) by whitespace. awk "{print $1}" prints the first column. Together with pipes, sed and awk let you transform any text data on the fly.

7

The Survival Toolkit

chmod β€” changes file permissions. chmod +x script.sh makes a file executable. curl β€” transfers data from URLs. Great for testing APIs and downloading files. wget β€” downloads files directly to disk. history β€” shows your recent commands. Use !42 to re-run command #42. alias β€” creates shortcuts: alias ll="ls -la" lets you type ll instead. top β€” shows running processes and resource usage, like a task manager.

8

The Survival Manual

A bash script is a file containing a sequence of commands, one per line. #!/bin/bash β€” the shebang. First line of every script. Tells the system to use bash. Variables β€” store values: NAME="world". Retrieve with $NAME. read β€” gets input from the user. echo β€” prints output. Scripts combine everything you've learned β€” file ops, pipes, text processing β€” into reusable programs. Save as .sh, make executable with chmod +x, run with ./script.sh.

Your Progress

0 of 8 lessons completed