Mastering the Linux Terminal: Commands That Save Hours
I used to use the GUI for everything. Searching text? VS Code. Renaming files? Finder. Then I watched a senior dev fix a production log issue in 10 seconds using grep and I was hooked.
The Power of Pipes |
Pipes let you pass the output of one command as input to another. This is the Unix philosophy: "Do one thing well."
# Find all error logs, count unique errors, sort by frequency
cat app.log | grep "ERROR" | cut -d: -f2 | sort | uniq -c | sort -nr
Grep: Search Like a Pro
grep stands for Global Regular Expression Print.
# Search recursively in current directory
grep -r "TODO" .
# Search literal string (faster), showing line numbers
grep -rnF "processPayment" src/
# Exclude node_modules
grep -r "API_KEY" . --exclude-dir=node_modules
Find: locating files
# Find all JavaScript files modified in last 24 hours
find . -name "*.js" -mtime -1
# Find and delete node_modules (careful!)
find . -name "node_modules" -type d -prune -exec rm -rf '{}' +
Sed: Stream Editor
Perfect for bulk changes.
# Replace 'http' with 'https' in all files
sed -i 's/http:/https:/g' config.js
# Print lines 10 to 20
sed -n '10,20p' file.txt
Awk: Text Processing
When you need to process columns of data.
# Print second column (PID) of processes named 'node'
ps aux | grep node | awk '{print $2}'
# Sum a column of numbers
cat expenses.txt | awk '{sum += $1} END {print sum}'
Custom Aliases
Add these to your .zshrc or .bashrc:
# Git shortcuts
alias gs='git status'
alias gc='git commit -m'
alias gp='git push'
# Easy navigation
alias ..='cd ..'
alias ...='cd ../..'
# Safety
alias rm='rm -i' # Ask before deleting
Useful Tools
- htop: Better Process Manager
- curl/httpie: API testing
- jq: JSON processor
- fzf: Fuzzy finder
JQ Example
# Pretty print JSON
curl https://api.github.com/users/octocat | jq .
# Extract specific field
curl ... | jq '.name'
Bash Scripting Basics
Create deploy.sh:
#!/bin/bash
set -e # Exit on error
echo "Building..."
npm run build
echo "Deploying..."
aws s3 sync dist/ s3://my-bucket
echo "Done!"
The terminal isn't scary—it's the fastest way to talk to your computer. Learn one new command a week.