Terminal Commands & Efficiency Tips
For developers, the Terminal is the second most important tool after the editor. Mastering the terminal can 5x your development efficiency.
๐ฅ Vibe Prompt
"Create a terminal efficiency guide: zsh configuration with oh-my-zsh themes and plugins, common pipeline command combinations, batch file processing, and VSCode integration tips."
Why Terminal Matters
GUI tools are intuitive but have limitations:
- No automation: Repeat the same operation 100 times manually
- No composability: Different tools can't be chained
- Slow: Mouse operations are far slower than keyboard
The Terminal solves all this:
- โ Scriptable automation
- โ Pipe (|) to compose multiple tools
- โ Much faster than GUI
Essential Commands
| Command | Purpose | Example |
|---------|---------|---------|
| ls | List files | ls -la detailed view |
| cd | Change directory | cd ~/projects |
| pwd | Print working directory | pwd |
| cp | Copy | cp -r src/ dest/ |
| mv | Move/rename | mv old.txt new.txt |
| rm | Delete | rm -rf temp/ |
| grep | Search text | grep -r "TODO" src/ |
| find | Search files | find . -name "*.py" |
| head/tail | First/last lines | tail -f app.log |
# Useful combos
# Search TODO in all Python files
find . -name "*.py" | xargs grep "TODO"
# Monitor logs in real-time
tail -f logs/app.log | grep "ERROR"
# Count lines of code
find . -name "*.ts" -o -name "*.tsx" | xargs wc -l | tail -1
# Find top 5 largest files
du -sh * | sort -rh | head -5
Pipelines & Redirection
# Pipeline: send output of one command to another
cat access.log | grep "404" | wc -l
# Returns: number of 404 errors
# Output redirection (> / >>)
echo "Hello" > file.txt # Write (overwrite)
echo "World" >> file.txt # Append
# Input redirection (<)
sort < unsorted.txt > sorted.txt
# Error redirection (2>)
command_that_fails 2> error.log
# Both stdout and stderr
command > output.log 2>&1
Oh-My-Zsh Configuration
# Install oh-my-zsh
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
# Recommended theme
ZSH_THEME="powerlevel10k/powerlevel10k"
# Recommended plugins
plugins=(
git
docker
docker-compose
node
npm
python
pip
vscode
history
colored-man-pages
zsh-autosuggestions
zsh-syntax-highlighting
web-search
copyfile
copypath
)
Advanced Tips
Useful Aliases
# Git
alias gs='git status'
alias ga='git add'
alias gc='git commit'
alias gp='git push'
alias gl='git log --oneline --graph'
# Docker
alias d='docker'
alias dc='docker-compose'
# Navigation
alias ..='cd ..'
alias ...='cd ../..'
# Safety
alias rm='rm -i'
fzf โ Fuzzy Finder
# Install
brew install fzf
# Search files and open with VSCode
vim $(fzf)
# Search command history
history | fzf
# Search and cd into directory
cd $(find . -type d | fzf)
Practice Exercise
๐ก Vibe Coding Practice: Ask AI to:
- Create a project initialization script (directory structure, git init, install deps)
- Create a one-click deploy script (test, build, upload)
- Configure terminal beautification (powerlevel10k + fonts)
- Create 20+ useful aliases
- Create batch processing scripts (batch rename, format conversion, cleanup)
Essential Terminal Commands
| Command | Purpose |
|---------|--------|
| ls -la | List files with details |
| cd ~/project | Change directory |
| pwd | Print working directory |
| mkdir -p a/b/c | Create nested directories |
| touch file.txt | Create empty file |
| cp -r src dest | Copy recursively |
| mv old new | Move/rename |
| rm -rf dir | Remove directory forcefully |
| find . -name "*.ts" | Find files by name |
| grep -r "function" . | Search for text |
| head -20 file.txt | First 20 lines |
| tail -f log.txt | Follow log in real-time |
| wc -l file.txt | Count lines |
| sort file.txt | Sort lines |
| uniq | Remove duplicates |
| chmod +x script.sh | Make executable |
Terminal Shortcuts
| Shortcut | Effect | |----------|--------| | Ctrl + C | Cancel current command | | Ctrl + D | Exit shell | | Ctrl + L | Clear screen | | Ctrl + A | Go to beginning of line | | Ctrl + E | Go to end of line | | Ctrl + R | Search command history | | Ctrl + W | Delete word before cursor | | Ctrl + U | Delete entire line | | Up/Down arrows | Navigate command history | | Tab | Auto-complete |
Piping and Redirection
# Pipe: send output of one command to another
grep "error" log.txt | wc -l # Count error lines
# Redirect output to file
npm run build > build.log 2>&1
# Append to file
echo "new entry" >> data.txt
# Pipe to multiple commands (tee)
get_data | tee output.txt | wc -l
Shell Scripting Basics
#!/bin/bash
# Variables
NAME="world"
echo "Hello, $NAME!"
# Command substitution
FILES=$(ls -la | wc -l)
echo "Number of files: $FILES"
# Conditionals
if [ -f "config.json" ]; then
echo "Config exists"
else
echo "Config missing"
fi
# Loops
for file in *.txt; do
echo "Processing $file"
wc -l "$file"
done
Summary
Terminal mastery is essential for developers. Learn basic commands, shortcuts, piping, and shell scripting to work efficiently.
Key takeaways:
- Basic commands: ls, cd, mkdir, cp, mv, rm |
- Search: find, grep |
- View: head, tail, cat, less |
- Count/sort: wc, sort, uniq |
- Shortcuts: Ctrl+C, Ctrl+R, Ctrl+A/E, Tab |
- Piping:
|connects commands | - Redirection:
>write,>>append | - Shell scripts automate repetitive tasks |
What's Next: AI Toolchain
The next chapter covers AI developer tools โ GitHub Copilot, Cursor, and prompt engineering.