---
title: "Terminal Codes & Commands"
category: "notes"
summary: "Essential terminal commands from my obsidian vault — macOS tips, productivity shortcuts, networking, and shell workflows."
date: "2026-07-31"
---

## Essential macOS & Linux Commands

| Command | Description |
|---------|-------------|
| `pwd` | Show current directory |
| `ls` | List directory contents |
| `ls -la` | List all files with details |
| `cd <dir>` | Change directory |
| `cd ..` | Go up one level |
| `mkdir -p <dir>` | Create directory recursively |
| `rm -rf <dir>` | Remove directory and contents |
| `cp -r <src> <dst>` | Copy directory recursively |
| `mv <old> <new>` | Move or rename |
| `cat <file>` | Print file contents |
| `less <file>` | View file page by page |
| `head -20 <file>` | First 20 lines |
| `tail -20 <file>` | Last 20 lines |
| `grep "pattern" <file>` | Search text in file |
| `find . -name "*.md"` | Find files by name |
| `which <cmd>` | Show command path |
| `whoami` | Current user |
| `uname -a` | System info |

## Productivity

| Command | Description |
|---------|-------------|
| `history` | Command history |
| `!!` | Repeat last command |
| `Ctrl + R` | Reverse search history |
| `Ctrl + C` | Cancel current command |
| `Ctrl + L` | Clear screen |
| `Ctrl + A` | Jump to line start |
| `Ctrl + E` | Jump to line end |
| `Alt + F` | Jump forward one word |
| `Alt + B` | Jump backward one word |
| `pbcopy` | Copy output to clipboard |
| `pbpaste` | Paste from clipboard |
| `caffeinate` | Prevent sleep |

## Networking

| Command | Description |
|---------|-------------|
| `ping <host>` | Check connectivity |
| `curl <url>` | Fetch URL content |
| `wget <url>` | Download file |
| `dig <domain>` | DNS lookup |
| `nslookup <domain>` | DNS resolution |
| `ifconfig` | Network interfaces |
| `netstat -tlnp` | Listening ports |
| `lsof -i :<port>` | Process using port |
| `traceroute <host>` | Trace network path |

## System

| Command | Description |
|---------|-------------|
| `top` | Real-time processes |
| `htop` | Interactive process viewer |
| `ps aux` | All processes |
| `kill <pid>` | Terminate process |
| `kill -9 <pid>` | Force terminate |
| `df -h` | Disk usage |
| `du -sh *` | Directory sizes |
| `free -h` | Memory usage |
| `uptime` | System uptime |

## Package Managers

| Command | Description |
|---------|-------------|
| `brew install <pkg>` | Install via Homebrew |
| `brew update` | Update Homebrew |
| `brew upgrade` | Upgrade all packages |
| `brew list` | Installed packages |
| `npm install <pkg>` | Install Node package |
| `pip install <pkg>` | Install Python package |
| `apt install <pkg>` | Install via APT (Linux) |

## Shell & Config

| Command | Description |
|---------|-------------|
| `echo $SHELL` | Current shell |
| `echo $PATH` | Search paths |
| `source ~/.zshrc` | Reload shell config |
| `alias ll='ls -la'` | Create alias |
| `export VAR=value` | Set environment variable |

## Quick Reference

- `cd ~` — go home
- `cd -` — go back
- `ls -lah` — all files with sizes
- `grep -r "text" .` — recursive search
- `find . -type f -name "*.md"` — find markdown files
- `wc -l <file>` — count lines
- `sort <file>` — sort lines
- `uniq <file>` — remove duplicates
- `tar -xzf <file>` — extract tar.gz
- `zip -r <out> <dir>` — create zip