🖥️ Terminal Cheat Sheet
macOS Terminal — navigation, file ops, nano, networking and more.
📝 Files & Directories
Create files & directories
touch file.txt mkdir my-folder mkdir -p parent/child/grandchild # create nested
Copy
cp file.txt copy.txt cp -r folder/ destination/ # recursive (folder)
Move / Rename
mv file.txt newname.txt mv file.txt ~/Documents/
Remove
rm file.txt rm -r folder/ # recursive rm -rf folder/ # force (no prompts) ⚠️
File size / disk usage
du -sh folder/ # folder size du -sh * # all in current dir df -h # disk usage
Symbolic link
ln -s /path/to/real /path/to/link
Find files
find . -name "*.dart" # by name find . -type f -name "*.json" # files only find . -mtime -1 # modified last 24h find . -size +1M # larger than 1MB
👁️ View & Search
View file content
cat file.txt less file.txt # scroll with arrows, q to quit head -20 file.txt # first 20 lines tail -20 file.txt # last 20 lines tail -f log.txt # follow live log
Search inside files (grep)
grep "pattern" file.txt grep -r "pattern" ./ # recursive grep -i "pattern" file.txt # case-insensitive grep -n "pattern" file.txt # with line numbers grep -l "pattern" ./*.dart # only file names
Count lines / words
wc -l file.txt # lines wc -w file.txt # words
Sort & unique
sort file.txt sort -r file.txt # reverse sort | uniq # remove duplicates sort | uniq -c # count occurrences
🔐 Permissions
Change permissions (chmod)
chmod 755 script.sh # rwxr-xr-x chmod +x script.sh # add execute chmod -w file.txt # remove write chmod -R 755 folder/ # recursive
Common chmod values
777 # rwxrwxrwx — full access (avoid!) 755 # rwxr-xr-x — scripts, dirs 644 # rw-r--r-- — files 600 # rw------- — private keys
Change owner (chown)
sudo chown user:group file.txt sudo chown -R user:group folder/
Run as superuser
sudo command sudo !! # re-run last command as sudo
⚙️ Process Management
List processes
ps aux # all processes ps aux | grep flutter # filter top # live process monitor htop # better top (brew install htop)
Kill process
kill PID # graceful kill -9 PID # force kill killall Xcode # by name pkill -f "flutter" # by pattern
Background & jobs
command & # run in background jobs # list background jobs fg %1 # bring job 1 to foreground Ctrl+Z # pause current process Ctrl+C # stop current process
Check port in use
lsof -i :8080 # who uses port 8080 lsof -i :8080 | grep LISTEN
🌐 Network
Ping & DNS
ping google.com ping -c 4 google.com # 4 times nslookup google.com dig google.com
HTTP requests (curl)
curl https://api.example.com
curl -X POST https://api.example.com/data \
-H "Content-Type: application/json" \
-d '{"key": "value"}'
curl -o file.txt https://example.com/fileNetwork interfaces
ifconfig # network interfaces ifconfig en0 # Wi-Fi info (IP address) netstat -an # active connections
SSH
ssh user@host ssh -i ~/.ssh/id_rsa user@host # with key ssh-keygen -t ed25519 -C "email" # generate key cat ~/.ssh/id_ed25519.pub # show public key
📄 Nano Editor
Open / create file in nano
nano file.txt nano ~/.zshrc
Essential nano shortcuts
Ctrl+O # Save (WriteOut) Enter # Confirm filename Ctrl+X # Exit Ctrl+K # Cut line Ctrl+U # Paste line Ctrl+W # Search Ctrl+\ # Search & replace Ctrl+G # Help Ctrl+A # Go to start of line Ctrl+E # Go to end of line Ctrl+_ # Go to line number
✏️ Vim Essentials
Open file in vim
vim file.txt
Modes & basic commands
i # Insert mode (start typing) Esc # Back to Normal mode :w # Save :q # Quit :wq # Save & quit :q! # Force quit without saving dd # Delete line yy # Copy line p # Paste below /pattern # Search (n = next, N = prev) :%s/old/new/g # Replace all
🍺 Homebrew (macOS)
Install Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Core commands
brew install package # install brew uninstall package # remove brew update # update Homebrew brew upgrade # upgrade all brew list # installed packages brew search name # search brew info package # package details brew doctor # diagnose issues
Cask (GUI apps)
brew install --cask visual-studio-code brew install --cask android-studio brew install --cask iterm2
⌨️ Terminal Shortcuts
Keyboard shortcuts
Ctrl+C # cancel current command Ctrl+D # exit / EOF Ctrl+L # clear screen Ctrl+A # move cursor to start of line Ctrl+E # move cursor to end of line Ctrl+U # clear from cursor to start Ctrl+K # clear from cursor to end Ctrl+W # delete word before cursor Ctrl+R # reverse search history !! # repeat last command !$ # last argument of previous command Tab # autocomplete
History
history # list command history history | grep git # search history !123 # run command #123
🐚 Zsh / Oh My Zsh
Install Oh My Zsh
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
Edit .zshrc
nano ~/.zshrc source ~/.zshrc # reload config
Add alias in .zshrc
alias gs="git status" alias gp="git push" alias fl="flutter" alias fpr="flutter pub run"
Add to PATH in .zshrc
export PATH="$PATH:/path/to/flutter/bin" export PATH="$PATH:$HOME/.pub-cache/bin"
Environment variables
export MY_VAR="value" echo $MY_VAR printenv # print all env vars