Greetings, brave adventurer! Welcome to the Terminal Fundamentals quest โ your gateway to the command line, the most powerful interface in any IT heroโs arsenal. While graphical interfaces are comfortable, the terminal is where real power lives. This quest will transform you from a GUI-bound novice into a confident command-line navigator.
cd, ls, and pwd to explore directoriesstdout, stderr, and stdinOpen Terminal.app (Applications โ Utilities โ Terminal) or install iTerm2 for an enhanced experience.
Open Windows Terminal or PowerShell. For a Unix-like experience, install WSL:
wsl --install
Open your distributionโs terminal emulator (GNOME Terminal, Konsole, or xterm).
Every adventurer must first learn to read a map. In the terminal, your map is the file system, and these commands are your compass.
# Print your current working directory
pwd
Expected Output:
/Users/yourusername
# List files and directories
ls
# List with details (permissions, size, date)
ls -l
# Show hidden files too (files starting with .)
ls -la
# Human-readable file sizes
ls -lh
# Go to a directory
cd Documents
# Go up one level
cd ..
# Go to your home directory
cd ~
# Go to the previous directory
cd -
# Go to an absolute path
cd /usr/local/bin
pwd to see where you arels -la to see all files including hidden onescdA hero must organize their inventory. Learn to create, copy, move, and remove items in the file system.
# Create a new directory
mkdir my-project
# Create nested directories at once
mkdir -p my-project/src/components
# Create an empty file
touch my-project/README.md
# Create a file with content
echo "Hello, World!" > my-project/hello.txt
# Copy a file
cp hello.txt hello-backup.txt
# Copy a directory (recursive)
cp -r my-project my-project-backup
# Move (or rename) a file
mv hello.txt greeting.txt
# Move a file into a directory
mv greeting.txt my-project/
# Remove a file
rm unwanted-file.txt
# Remove an empty directory
rmdir empty-folder
# Remove a directory and all its contents (use with caution!)
rm -r old-project
# Interactive mode โ asks before each deletion
rm -i important-file.txt
โ ๏ธ Warning: rm is permanent. There is no trash can in the terminal!
# Display entire file content
cat README.md
# Display with line numbers
cat -n README.md
# View first 10 lines
head README.md
# View last 10 lines
tail README.md
# Page through a long file (press q to quit)
less long-file.txt
terminal-practicetouchcatNow youโll learn the advanced incantations that chain simple commands into powerful spells.
command [flags/options] [arguments]
Examples:
ls -la /home # command: ls, flags: -la, argument: /home
grep -i "error" log # command: grep, flags: -i, arguments: "error" log
cp -r src/ dest/ # command: cp, flag: -r, arguments: src/ dest/
Pipes (|) send the output of one command as input to the next:
# List files and search for a pattern
ls -la | grep ".md"
# Count the number of files in a directory
ls | wc -l
# Sort files by size (largest first)
ls -lS | head -5
# Find all unique file extensions
ls | sed 's/.*\.//' | sort | uniq
# Write output to a file (overwrites existing content)
echo "Hello" > output.txt
# Append output to a file
echo "World" >> output.txt
# Redirect errors to a file
command-that-fails 2> errors.txt
# Redirect both output and errors
command 2>&1 > all-output.txt
# Search for text inside files
grep "TODO" *.md
# Search recursively in directories
grep -r "function" src/
# Case-insensitive search
grep -i "error" logfile.txt
# Find files by name
find . -name "*.md"
# Find files modified in the last 24 hours
find . -mtime -1
ls | wc -l to count files in your home directorygrep to search for a word in a file you createdls -la to a file called file-list.txtfind to locate all .md files in a directoryproject/{src,docs,tests}ls -Rgrep to find lines containing โerrorโ or โwarningโwc -l to count how many errors existfind and pipes to locate and process filesls -la redirected to a filecd with relative and absolute paths