Last Updated: 2026-02-06 by Keming He
Important
This guide is for macOS / Linux users with POSIX-compatible shell (sh, bash, zsh).
For Windows users: See WSL (Windows Subsystem for Linux) or PowerShell.
Essential shell commands for developer workflows.
find . -name "*.md" # Find by name (current dir)
find . -iname "readme*" # Case-insensitive
find . -type f -name "*.js" # Files only
find . -type d -name "src" # Directories only
find . -mtime -7 # Modified in last 7 daysgrep "pattern" file.txt # Search in file
grep -r "pattern" . # Recursive search
grep -i "pattern" file.txt # Case-insensitive
grep -n "pattern" file.txt # Show line numbers
grep -l "pattern" *.md # List matching filesfind . -name "*.js" -exec grep -l "TODO" {} \; # Find files containing TODOcat file.txt # Entire file
head -20 file.txt # First 20 lines
tail -20 file.txt # Last 20 lines
tail -f log.txt # Follow updates (logs)
less file.txt # Scrollable view (q to quit)wc -l file.txt # Count lines
file document.pdf # Identify file typepwd # Current directory
cd /path/to/dir # Change directory
cd .. # Up one level
cd - # Previous directory
cd ~ # Home directoryls -la # Detailed with hidden files
ls -lh # Human-readable sizes
ls -lt # Sort by modification time
tree -L 2 # Tree view, 2 levels (if installed)Prevents interactive/pager mode. Essential for scripts and AI agents.
git diff | cat # Avoid interactive diff
git log | cat # Disable pager
git status | cat # Full output, no interactioncommand > file.txt # Overwrite file
command >> file.txt # Append to file
command > /dev/null # Discard stdout
command 2> /dev/null # Discard stderr
command > /dev/null 2>&1 # Discard all output
command 2>&1 | tee output.txt # Save and displaymkdir directory # Create directory
mkdir -p path/to/nested/dir # Create nested directories
touch file.txt # Create empty filecp source.txt dest.txt # Copy file
cp -r source/ dest/ # Copy directory
mv old.txt new.txt # Rename/moverm file.txt # Delete file
rm -r directory/ # Delete directory
rmdir empty-dir/ # Delete empty directory only