Loading
Master pipes, redirects, grep, find, environment variables, aliases, and shell scripts to work faster in the terminal.
You know cd, ls, and mkdir. Good. Now it is time to learn the features that make the terminal genuinely faster than a GUI. These are the tools that senior developers use every day without thinking about them.
The pipe operator | takes the output of one command and feeds it as input to another. This lets you chain small tools together into powerful operations.
Redirects send output to files instead of the screen:
The key distinction: > overwrites, >> appends, 2> redirects errors, and 2>&1 combines error output with standard output.
grep searches for patterns in files. It is the fastest way to find where something is used in a codebase.
Combine grep with pipes for more targeted searches:
For large codebases, ripgrep (rg) is significantly faster than grep and ignores .gitignore entries by default. If your system has it, prefer it.
find locates files by name, type, size, or modification time.
Combine find with -exec to run a command on each result:
Environment variables store configuration that changes between environments — API URLs, feature flags, debug settings.
Your shell loads variables from configuration files on startup:
~/.bashrc or ~/.zshrc — loaded for every new terminal session~/.bash_profile or ~/.zprofile — loaded for login shells.env files — loaded by tools like Next.js, Docker, or dotenvAfter editing your shell config, reload it:
Aliases replace long commands with short ones. Add these to your ~/.zshrc or ~/.bashrc:
For anything more complex than a simple replacement, use a function:
After adding aliases or functions, run source ~/.zshrc to load them immediately.
When a task takes more than one command and you do it regularly, write a script.
Save it, make it executable, and run it:
A more practical example — a script that checks if your code is ready to commit:
The set -e line is important — it makes the script stop at the first failure instead of continuing after an error.
Useful patterns for scripts:
The terminal is a multiplier. Every alias you create, every script you write, and every pipe you chain saves time on every future use. Start with the commands you type most often and automate outward from there.
# Count how many JavaScript files exist in your project
find . -name "*.js" | wc -l
# Show the 10 largest files in a directory
du -sh * | sort -rh | head -10
# List all unique file extensions in your project
find . -type f | sed 's/.*\.//' | sort -u# Write output to a file (overwrites)
echo "Hello" > output.txt
# Append output to a file
echo "World" >> output.txt
# Redirect errors to a file
npm run build 2> errors.log
# Redirect both output and errors
npm run build > build.log 2>&1# Find all files containing "useState"
grep -r "useState" src/
# Case-insensitive search
grep -ri "error" src/
# Show line numbers
grep -rn "TODO" src/
# Show 3 lines of context around each match
grep -rn -C 3 "fetchUser" src/
# Search only specific file types
grep -rn "className" --include="*.tsx" src/
# Invert match: show lines that do NOT contain a pattern
grep -v "node_modules" file.txt# Find all exports in TypeScript files
grep -rn "^export" --include="*.ts" src/ | grep -v "node_modules"
# Count how many times a function is called
grep -r "formatDate" src/ | wc -l# Find all TypeScript files
find src/ -name "*.ts"
# Find all directories named "components"
find src/ -type d -name "components"
# Find files modified in the last 24 hours
find src/ -mtime -1
# Find files larger than 1MB
find . -size +1M
# Find and delete all .DS_Store files
find . -name ".DS_Store" -delete
# Find empty directories
find . -type d -empty# Find all PNG files and list their sizes
find . -name "*.png" -exec ls -lh {} \;
# Find all test files and count lines of code
find src/ -name "*.test.ts" -exec wc -l {} +# Set a variable for the current session
export API_URL="http://localhost:3000"
# Use it in a command
curl $API_URL/health
# See all environment variables
env
# See a specific variable
echo $PATH
# Set a variable for just one command
NODE_ENV=production npm run build# Add to ~/.zshrc to persist across sessions
export EDITOR="code"
export PATH="$HOME/.local/bin:$PATH"source ~/.zshrc# Git shortcuts
alias gs="git status"
alias gc="git commit"
alias gp="git push"
alias gl="git log --oneline -20"
alias gd="git diff"
# Project shortcuts
alias dev="npm run dev"
alias build="npm run build"
alias lint="npm run lint"
# Navigation
alias ..="cd .."
alias ...="cd ../.."
alias projects="cd ~/projects"# Create a directory and cd into it
mkcd() {
mkdir -p "$1" && cd "$1"
}
# Kill whatever is running on a specific port
killport() {
lsof -ti:$1 | xargs kill -9
}
# Quick git add, commit, push
gcp() {
git add -A && git commit -m "$1" && git push
}#!/bin/bash
# setup.sh — Set up the project for development
echo "Installing dependencies..."
npm install
echo "Setting up environment..."
cp .env.example .env.local
echo "Running database migrations..."
npx supabase db push
echo "Starting dev server..."
npm run devchmod +x setup.sh
./setup.sh#!/bin/bash
# precheck.sh — Run all checks before committing
set -e # Exit on first error
echo "Running type check..."
npm run typecheck
echo "Running linter..."
npm run lint
echo "Running build..."
npm run build
echo "All checks passed."# Check if a command exists
if command -v docker &> /dev/null; then
echo "Docker is installed"
else
echo "Docker is not installed"
exit 1
fi
# Accept arguments
echo "Deploying to $1..." # ./deploy.sh production
# Use variables
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
BACKUP_FILE="backup_$TIMESTAMP.sql"