# Command Line Cheatsheet

A quick refresher for common shell commands.

## Navigation & Files

| Command | What it does | Example |
|---|---|---|
| `ls` | Lists directory contents. | `ls -la` |
| `pwd` | Prints the current working directory. | `pwd` |
| `cd` | Changes the current directory. | `cd ~/projects` |
| `mkdir` | Creates a directory. | `mkdir -p src/utils` |
| `touch` | Creates an empty file or updates its timestamp. | `touch notes.txt` |
| `nano` | Opens a simple terminal text editor. | `nano config.yml` |
| `cp` | Copies files or directories. | `cp -r src/ backup/` |
| `mv` | Moves or renames files and directories. | `mv old.txt new.txt` |
| `rm` | Deletes files or directories. | `rm -rf build/` |
| `rmdir` | Removes an empty directory. | `rmdir old_dir` |

## Viewing & Searching

| Command | What it does | Example |
|---|---|---|
| `cat` | Prints a file's contents to the terminal. | `cat README.md` |
| `less` | Views a file one page at a time (`q` to quit). | `less server.log` |
| `head` | Shows the first lines of a file. | `head -n 20 data.csv` |
| `tail` | Shows the last lines of a file; `-f` follows updates. | `tail -f app.log` |
| `grep` | Searches text for a pattern. | `grep -rn "TODO" src/` |
| `find` | Searches for files by name, type, or other criteria. | `find . -name "*.js"` |
| `which` | Shows the path of an executable. | `which python3` |
| `man` | Opens the manual page for a command. | `man grep` |

## System & Shell

| Command | What it does | Example |
|---|---|---|
| `echo` | Prints text or variable values. | `echo "Hello, $USER"` |
| `whoami` | Prints the current username. | `whoami` |
| `sudo` | Runs a command with superuser privileges. | `sudo apt update` |
| `chmod` | Changes file permissions. | `chmod +x script.sh` |
| `clear` | Clears the terminal screen. | `clear` |
| `history` | Lists previously run commands. | `history \| grep git` |
| `curl` | Transfers data to or from a URL. | `curl -L https://example.com` |
| `source` | Runs a script in the current shell session. | `source ~/.bashrc` |
| `export` | Sets an environment variable for child processes. | `export API_KEY=abc123` |
| `git` | Tracks and manages changes in a code repository. | `git commit -m "Fix bug"` |
| `bash` | Starts a Bash shell or runs a script with it. | `bash script.sh` |