Command Line Basics
Learn about Command Line Basics
Before mastering Git, you need to be comfortable with the command line. Git is primarily a terminal tool, and knowing basic navigation commands will make your Git workflow significantly faster. This episode covers the essential terminal commands you'll use alongside Git every day.
Opening the Terminal
- macOS: Open Terminal (Cmd + Space, type "Terminal") or iTerm2
- Windows: Open Git Bash (installed with Git) or PowerShell
- Linux: Open Terminal (Ctrl + Alt + T on most distros)
- VS Code: Press
Ctrl + `to toggle the built-in terminal
Navigating Directories
# Print current directory (where you are)
pwd
# Output: /Users/yourname
# List files and folders
ls # Basic list
ls -la # Detailed list (includes hidden files like .git)
ls -lah # Same but with human-readable file sizes
# Change directory
cd Documents # Go into Documents
cd Documents/projects # Go deeper
cd .. # Go up one level
cd ../.. # Go up two levels
cd ~ # Go to home directory
cd / # Go to root directory
cd - # Go back to previous directory
Creating and Removing
# Create a directory
mkdir my-project
mkdir -p projects/web/my-app # Create nested directories
# Create a file
touch index.html
touch src/app.js src/utils.js # Create multiple files
# Remove a file
rm old-file.txt
# Remove a directory (must be empty)
rmdir empty-folder
# Remove a directory and ALL contents (careful!)
rm -rf my-folder
Moving and Copying
# Copy a file
cp original.txt copy.txt
cp original.txt ../backup/ # Copy to another directory
# Copy a directory
cp -r src/ backup-src/
# Move (or rename) a file
mv old-name.txt new-name.txt # Rename
mv file.txt ../documents/ # Move to another directory
# Move a directory
mv old-folder/ new-location/
Reading Files
# Display file contents
cat README.md
# Display with line numbers
cat -n app.js
# View large files page by page
less large-file.log
# Press 'q' to quit, Space for next page, 'b' for previous
# View first/last lines
head -20 file.txt # First 20 lines
tail -20 file.txt # Last 20 lines
Useful Shortcuts
# Tab completion — saves so much typing!
cd Doc[TAB] # Auto-completes to "Documents"
# Command history
history # Show recent commands
# Up/Down arrows to cycle through previous commands
# Clear the screen
clear # Or press Ctrl + L
# Cancel a running command
# Ctrl + C
# Search previous commands
# Ctrl + R, then type to search
Working with Paths
# Absolute path — starts from root
cd /Users/yourname/projects/my-app
# Relative path — relative to current location
cd projects/my-app # From home directory
cd ./src # ./ means "current directory"
cd ../other-project # ../ means "parent directory"
Finding Things
# Find files by name
find . -name "*.js" # All .js files in current directory tree
find . -name "package.json" # Find specific file
# Search inside files
grep "TODO" src/*.js # Find "TODO" in JS files
grep -r "function" src/ # Search recursively in a directory
grep -rn "error" logs/ # With line numbers
What's Next
You're now comfortable with the terminal. In the next episode, we'll create your first Git repository and understand the .git directory — the brain of every Git project.