Updated formattting

This commit is contained in:
Mikael Johansson 2026-06-14 12:47:24 +02:00
parent e5bffd2fe1
commit 9012a85e30
3 changed files with 73 additions and 73 deletions

View File

@ -17,22 +17,22 @@ int main() {
| Command | What it does | Example |
|---------|-------------|---------|
| `clang++ <file>` | Compile to an executable named `a.out` | `clang++ hello.cpp` |
| `clang++ <file> -o <name>` | Compile and name the output | `clang++ hello.cpp -o hello` |
| `clang++ -Wall <file>` | Enable **all** warnings (always use this!) | `clang++ -Wall hello.cpp -o hello` |
| `clang++ -std=c++17 <file>` | Use a specific C++ version | `clang++ -std=c++20 -Wall prog.cpp -o prog` |
| `clang++ -g <file>` | Include debug info (for use with a debugger) | `clang++ -g -Wall hello.cpp -o hello` |
| clang++ <file> | Compile to an executable named a.out | clang++ hello.cpp |
| clang++ <file> -o <name> | Compile and name the output | clang++ hello.cpp -o hello |
| clang++ -Wall <file> | Enable **all** warnings (always use this!) | clang++ -Wall hello.cpp -o hello |
| clang++ -std=c++17 <file> | Use a specific C++ version | clang++ -std=c++20 -Wall prog.cpp -o prog |
| clang++ -g <file> | Include debug info (for use with a debugger) | clang++ -g -Wall hello.cpp -o hello |
**Common flags explained:**
| Flag | Meaning |
|------|---------|
| `-o <name>` | Output filename (instead of `a.out`) |
| `-Wall` | Enable most compiler warnings |
| `-Wextra` | Enable even more warnings |
| `-std=c++17` | Use C++17 standard (also `c++11`, `c++14`, `c++20`) |
| `-g` | Include debug symbols (for `gdb` or `lldb`) |
| `-O2` | Optimize for speed |
| -o <name> | Output filename (instead of a.out) |
| -Wall | Enable most compiler warnings |
| -Wextra | Enable even more warnings |
| -std=c++17 | Use C++17 standard (also c++11, c++14, c++20) |
| -g | Include debug symbols (for gdb or lldb) |
| -O2 | Optimize for speed |
### Full compile example
```bash
@ -91,9 +91,9 @@ clean:
| Command | What it does |
|---------|-------------|
| `make` | Build the program |
| `make clean` | Delete the compiled program |
| `make -j4` | Build using 4 CPU cores (faster) |
| make | Build the program |
| make clean | Delete the compiled program |
| make -j4 | Build using 4 CPU cores (faster) |
### Typical Makefile with separate compilation
```make

View File

@ -4,15 +4,15 @@
| Command | What it does | Example |
|---------|-------------|---------|
| `git config --global user.name "Your Name"` | Set your name on commits | `git config --global user.name "Alice"` |
| `git config --global user.email "a@b.com"` | Set your email on commits | `git config --global user.email "alice@example.com"` |
| git config --global user.name "Your Name" | Set your name on commits | git config --global user.name "Alice" |
| git config --global user.email "a@b.com" | Set your email on commits | git config --global user.email "alice@example.com" |
## Starting a Project
| Command | What it does | Example |
|---------|-------------|---------|
| `git init` | Turn the current folder into a Git repo | `cd my_project && git init` |
| `git clone <url>` | Download an existing repo from GitHub etc. | `git clone https://github.com/user/repo.git` |
| git init | Turn the current folder into a Git repo | cd my_project && git init |
| git clone <url> | Download an existing repo from GitHub etc. | git clone https://github.com/user/repo.git |
## Everyday Workflow
@ -25,43 +25,43 @@
| Command | What it does | Example |
|---------|-------------|---------|
| `git status` | See what files changed and what's staged | `git status` |
| `git add <file>` | Stage a file for commit | `git add main.cpp` |
| `git add .` | Stage **all** changed files | `git add .` |
| `git commit -m "message"` | Save staged changes with a message | `git commit -m "Add login feature"` |
| `git log` | Show commit history | `git log --oneline` (compact view) |
| `git diff` | Show unstaged changes (line by line) | `git diff` |
| git status | See what files changed and what's staged | git status |
| git add <file> | Stage a file for commit | git add main.cpp |
| git add . | Stage **all** changed files | git add . |
| git commit -m "message" | Save staged changes with a message | git commit -m "Add login feature" |
| git log | Show commit history | git log --oneline (compact view) |
| git diff | Show unstaged changes (line by line) | git diff |
## Undoing Things
| Command | What it does | Example |
|---------|-------------|---------|
| `git restore <file>` | Discard unstaged changes in a file | `git restore main.cpp` |
| `git restore --staged <file>` | Unstage a file (keep your edits) | `git restore --staged main.cpp` |
| `git commit --amend -m "new msg"` | Fix the last commit message | `git commit --amend -m "Fixed message"` |
| `git reset --hard HEAD` | Throw away **all** uncommitted changes ⚠️ | Use with care! |
| git restore <file> | Discard unstaged changes in a file | git restore main.cpp |
| git restore --staged <file> | Unstage a file (keep your edits) | git restore --staged main.cpp |
| git commit --amend -m "new msg" | Fix the last commit message | git commit --amend -m "Fixed message" |
| git reset --hard HEAD | Throw away **all** uncommitted changes ⚠️ | Use with care! |
## Branches
| Command | What it does | Example |
|---------|-------------|---------|
| `git branch` | List branches (`*` = current one) | `git branch` |
| `git branch <name>` | Create a new branch | `git branch feature-x` |
| `git checkout <branch>` | Switch to a branch | `git checkout feature-x` |
| `git switch <branch>` | Switch to a branch (newer syntax) | `git switch main` |
| `git checkout -b <name>` | Create **and** switch to a new branch | `git checkout -b feature-x` |
| `git merge <branch>` | Merge another branch into the current one | `git switch main && git merge feature-x` |
| `git branch -d <name>` | Delete a branch (safe) | `git branch -d feature-x` |
| git branch | List branches (* = current one) | git branch |
| git branch <name> | Create a new branch | git branch feature-x |
| git checkout <branch> | Switch to a branch | git checkout feature-x |
| git switch <branch> | Switch to a branch (newer syntax) | git switch main |
| git checkout -b <name> | Create **and** switch to a new branch | git checkout -b feature-x |
| git merge <branch> | Merge another branch into the current one | git switch main && git merge feature-x |
| git branch -d <name> | Delete a branch (safe) | git branch -d feature-x |
## Working with GitHub (Remote)
| Command | What it does | Example |
|---------|-------------|---------|
| `git remote add origin <url>` | Link your local repo to GitHub | `git remote add origin https://github.com/alice/my-project.git` |
| `git push -u origin main` | Push commits to GitHub (first time) | `git push -u origin main` |
| `git push` | Push commits (after first time) | `git push` |
| `git pull` | Fetch and merge the latest from GitHub | `git pull` |
| `git fetch` | Download updates from GitHub (don't merge) | `git fetch` |
| git remote add origin <url> | Link your local repo to GitHub | git remote add origin https://github.com/alice/my-project.git |
| git push -u origin main | Push commits to GitHub (first time) | git push -u origin main |
| git push | Push commits (after first time) | git push |
| git pull | Fetch and merge the latest from GitHub | git pull |
| git fetch | Download updates from GitHub (don't merge) | git fetch |
## Common Scenarios

View File

@ -4,59 +4,59 @@
| Command | What it does | Example |
|---------|-------------|---------|
| `pwd` | Print the current directory (where you are) | `pwd``/home/alice` |
| `ls` | List files and folders | `ls`, `ls -la` (detailed view) |
| `cd <dir>` | Change directory | `cd Documents`, `cd ~` (home), `cd ..` (up one) |
| `mkdir <name>` | Create a new directory | `mkdir projects` |
| `rmdir <dir>` | Remove an **empty** directory | `rmdir old_folder` |
| pwd | Print the current directory (where you are) | pwd → /home/alice |
| ls | List files and folders | ls, ls -la (detailed view) |
| cd <dir> | Change directory | cd Documents, cd ~ (home), cd .. (up one) |
| mkdir <name> | Create a new directory | mkdir projects |
| rmdir <dir> | Remove an **empty** directory | rmdir old_folder |
## File Operations
| Command | What it does | Example |
|---------|-------------|---------|
| `touch <file>` | Create an empty file | `touch notes.txt` |
| `cp <src> <dst>` | Copy a file | `cp notes.txt backup.txt` |
| `mv <src> <dst>` | Move or rename a file | `mv notes.txt ~/Documents/` |
| `rm <file>` | Delete a file (⚠️ no trash bin) | `rm temp.txt` |
| `rm -r <dir>` | Delete a folder and **everything inside** | `rm -r old_project/` |
| `cat <file>` | Print a file's contents to the terminal | `cat notes.txt` |
| `less <file>` | View a file page-by-page (press `q` to quit) | `less long_file.txt` |
| `head <file>` | Show the first 10 lines | `head data.csv` |
| `tail <file>` | Show the last 10 lines | `tail -n 20 data.csv` |
| `nano <file>` | Edit a file in the terminal | `nano notes.txt` |
| touch <file> | Create an empty file | touch notes.txt |
| cp <src> <dst> | Copy a file | cp notes.txt backup.txt |
| mv <src> <dst> | Move or rename a file | mv notes.txt ~/Documents/ |
| rm <file> | Delete a file (⚠️ no trash bin) | rm temp.txt |
| rm -r <dir> | Delete a folder and **everything inside** | rm -r old_project/ |
| cat <file> | Print a file's contents to the terminal | cat notes.txt |
| less <file> | View a file page-by-page (press q to quit) | less long_file.txt |
| head <file> | Show the first 10 lines | head data.csv |
| tail <file> | Show the last 10 lines | tail -n 20 data.csv |
| nano <file> | Edit a file in the terminal | nano notes.txt |
## Viewing & Finding
| Command | What it does | Example |
|---------|-------------|---------|
| `file <name>` | Show what type of file something is | `file notes.txt` |
| `find <dir> -name <pattern>` | Find files by name | `find ~ -name "*.md"` |
| `grep <pattern> <file>` | Search inside files | `grep "error" log.txt` |
| file <name> | Show what type of file something is | file notes.txt |
| find <dir> -name <pattern> | Find files by name | find ~ -name "*.md" |
| grep <pattern> <file> | Search inside files | grep "error" log.txt |
## Permissions
| Command | What it does | Example |
|---------|-------------|---------|
| `chmod <mode> <file>` | Change file permissions | `chmod +x script.sh` (make executable) |
| `sudo <command>` | Run a command as admin (root) | `sudo apt update` |
| chmod <mode> <file> | Change file permissions | chmod +x script.sh (make executable) |
| sudo <command> | Run a command as admin (root) | sudo apt update |
## Package Management (apt)
| Command | What it does | Example |
|---------|-------------|---------|
| `sudo apt update` | Refresh the list of available packages | Run before installing anything |
| `sudo apt install <pkg>` | Install a package | `sudo apt install clang` |
| `sudo apt upgrade` | Upgrade all installed packages | `sudo apt upgrade` |
| `sudo apt remove <pkg>` | Uninstall a package | `sudo apt remove clang` |
| `apt search <keyword>` | Search for a package | `apt search image editor` |
| sudo apt update | Refresh the list of available packages | Run before installing anything |
| sudo apt install <pkg> | Install a package | sudo apt install clang |
| sudo apt upgrade | Upgrade all installed packages | sudo apt upgrade |
| sudo apt remove <pkg> | Uninstall a package | sudo apt remove clang |
| apt search <keyword> | Search for a package | apt search image editor |
## Pipes & Redirection
| Command | What it does | Example |
|---------|-------------|---------|
| `cmd1 \| cmd2` | Send output of `cmd1` into `cmd2` | `ls \| grep ".txt"` |
| `>` | Redirect output to a file (overwrite) | `echo "hello" > hello.txt` |
| `>>` | Redirect output to a file (append) | `echo "world" >> hello.txt` |
| cmd1 \| cmd2 | Send output of cmd1 into cmd2 | ls \| grep ".txt" |
| > | Redirect output to a file (overwrite) | echo "hello" > hello.txt |
| >> | Redirect output to a file (append) | echo "world" >> hello.txt |
## WSL-Specific Tips
@ -69,11 +69,11 @@
| Shortcut | What it does |
|----------|-------------|
| `Ctrl + C` | Cancel the current command |
| `Ctrl + D` | Exit the terminal / close session |
| `Tab` | Auto-complete file and folder names |
| `` / `` | Scroll through command history |
| `Ctrl + L` | Clear the screen |
| Ctrl + C | Cancel the current command |
| Ctrl + D | Exit the terminal / close session |
| Tab | Auto-complete file and folder names |
| ↑ / ↓ | Scroll through command history |
| Ctrl + L | Clear the screen |
## Quick Reference — First Steps