diff --git a/chapters/append/cheatsheets.qmd b/chapters/append/cheatsheets.qmd index 6c8c9c56..34b5c1c9 100644 --- a/chapters/append/cheatsheets.qmd +++ b/chapters/append/cheatsheets.qmd @@ -1,610 +1,593 @@ # Cheatsheets {#sec-append-cheat} -## Environments as Code +## Environments as code ### Checking library + repository status -| Step | R Command | Python Command | -|----------------------------------------------|------------------|----------------| -| Check whether library in sync with lockfile. | `renv::status()` | None | +| Step | R Command | Python Command | +|------------------------------------|------------------|------------------| +| Check whether library is in sync with lockfile. | `re nv::status()` | None | -### Creating and Using a Standalone Project Library +### Creating and using a standalone project library Make sure you're in a standalone project library. -+-------------------------+-------------------+-----------------------+ -| **Step** | R Command | Python Command | -+-------------------------+-------------------+-----------------------+ -| Create a standalone | `renv::init()` | ` | -| library. | | python -m venv ` | -| | | | -| Tip: Make sure you've | | Convention: | -| got `{renv}`/`{venv}`: | | use`.venv` for | -| `in | | `` | -| stall.packages("renv")` | | | -| `{venv}` included w/ | | | -| Python 3.5+ | | | -+-------------------------+-------------------+-----------------------+ -| Activate project | ` | `source | -| library. | renv::activate()` | /bin/activate` | -| | | | -| | Happens | | -| | automatically if | | -| | in RStudio | | -| | project. | | -+-------------------------+-------------------+-----------------------+ -| Install packages as | `install.p | `python | -| normal. | ackages("")` | -m pip install ` | -+-------------------------+-------------------+-----------------------+ -| Snapshot package state. | ` | `pip freez | -| | renv::snapshot()` | e > requirements.txt` | -+-------------------------+-------------------+-----------------------+ -| Exit project | Leave R project | `deactivate` | -| environment. | or | | -| | `re | | -| | nv::deactivate()` | | -+-------------------------+-------------------+-----------------------+ + +++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Step

R Command

Python Command

Create a standalone library.

renv::init()

+

Tip: get {renv} w/ +install.p ackages("renv")

p ython -m venv <dir>

+

Convention: use.venv for <dir>

+

Tip: {venv} included w/ Python 3.5+

Activate project library.

r env::activate()

+

Happens automatically if in RStudio project.

source <dir> /bin/activate

Install packages as normal.

install.pa ckages("<pkg>")

python - m pip install <pkg>

Snapshot package state.

r env::snapshot()

pip freeze > requirements.txt

Exit project environment.

Leave R project or re n v::deactivate()

deactivate

### Collaborating on someone else's project Start by downloading the project into a directory on your machine. -+-----------------+-----------------+--------------------------------+ -| **Step** | **R Command** | **Python Command** | -+-----------------+-----------------+--------------------------------+ -| Move into | `set wd ("< | `cd ` | -| project | project-dir>")` | | -| directory. | | | -| | Or open project | | -| | in RStudio. | | -+-----------------+-----------------+--------------------------------+ -| Create project | `renv::init()` | `python -m venv ` | -| environment. | | | -| | | Recommend: use `.venv` for | -| | | `` | -+-----------------+-----------------+--------------------------------+ -| Enter project | Happens | `source /bin/activate` | -| environment. | automatically | | -| | or | | -| | `re | | -| | nv::activate()` | | -+-----------------+-----------------+--------------------------------+ -| Restore | Happens | `pi | -| packages. | automatically | p install -r requirements.txt` | -| | or | | -| | `r | | -| | env::restore()` | | -+-----------------+-----------------+--------------------------------+ - -## HTTP Code Cheatsheet {#cheat-http} - -As you work more with HTTP traffic, you'll learn some of the common -codes. Here's a cheatsheet for some of the most frequent you'll see. - -+-------------------+-----------------------------------------------+ -| Code | Meaning | -+===================+===============================================+ -| `200` | Everyone's favorite, a successful response. | -+-------------------+-----------------------------------------------+ -| `3xx` | Your query was redirected somewhere else, | -| | usually ok. | -+-------------------+-----------------------------------------------+ -| `4xx` | Errors with the request | -+-------------------+-----------------------------------------------+ -| `400` | Bad request. This isn't a request the server | -| | can understand. | -+-------------------+-----------------------------------------------+ -| `401` and `403` | Unauthorized or forbidden. Required | -| | authentication hasn't been provided. | -+-------------------+-----------------------------------------------+ -| `404` | Not found. There isn't any content to access | -| | here. | -+-------------------+-----------------------------------------------+ -| `5xx` | Errors with the server once your request got | -| | there. | -+-------------------+-----------------------------------------------+ -| `500` | Generic server-side error. Your request was | -| | received, but there was an error processing | -| | it. | -+-------------------+-----------------------------------------------+ -| `504` | Gateway timeout. This means that a proxy or | -| | gateway between you and the server you're | -| | trying to access timed out before it got a | -| | response from the server. | -+-------------------+-----------------------------------------------+ + +++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Step

R Command

Python Command

Move into project directory.

set wd ("< p roject-dir>")

+

Or open project in RStudio.

cd <project-dir>

Create project environment.

renv::init()

python -m venv <dir>

+

Recommend: use .venv for +<dir>

Enter project environment.

Happens automatically or ren v::activate()

source <dir> /bin/activate

Restore packages.

Happens automatically or re nv::restore()

pip install -r requirements.txt

+ +## HTTP code cheatsheet {#cheat-http} + +As you work with HTTP traffic, you'll learn some of the common codes. +Here's are some of those used most frequently. + +| Code | Meaning | +|----------------------|--------------------------------------------------| +| $200$ | Everyone's favorite, a successful response. | +| $\text{3xx}$ | Your query was redirected somewhere else, usually ok. | +| $\text{4xx}$ | Errors with the request | +| $400$ | Bad request. This isn't a request the server can understand. | +| $401$/$403$ | Unauthorized or forbidden. Required authentication hasn't been provided. | +| $404$ | Not found. There isn't any content to access here. | +| $\text{5xx}$ | Errors with the server once your request got there. | +| $500$ | Generic server-side error. Your request was received, but there was an error processing it. | +| $504$ | Gateway timeout. This means that a proxy or gateway between you and the server you're trying to access timed out before it got a response from the server. | ## Git {#cheat-git} -+----------------------+---------------------------------------+ -| **Command** | **What it does** | -+----------------------+---------------------------------------+ -| `git clone ` | Clone a remote repo -- make sure | -| | you're using SSH URL. | -+----------------------+---------------------------------------+ -| ` | Add files/dir to staging area. | -| git add ` | | -+----------------------+---------------------------------------+ -| `git | Commit staging area. | -| commit -m ` | | -+----------------------+---------------------------------------+ -| `git p | Push to a remote. | -| ush origin ` | | -+----------------------+---------------------------------------+ -| `git p | Pull from a remote. | -| ull origin ` | | -+----------------------+---------------------------------------+ -| `git che | Checkout a branch. | -| ckout ` | | -+----------------------+---------------------------------------+ -| `git checko | Create and checkout a branch. | -| ut -b ` | | -+----------------------+---------------------------------------+ -| `git bran | Delete a branch. | -| ch -d ` | | -+----------------------+---------------------------------------+ +| | | +|---------------------------|---------------------------------------------| +| **Command** | **What it does** | +| `git clone ` | Clone a remote repo -- make sure you're using SSH URL. | +| `git add ` | Add files/directory to staging area. | +| `git commit -m ` | Commit staging area. | +| `git push origin ` | Push to a remote. | +| `git pull origin ` | Pull from a remote. | +| `git checkout ` | Checkout a branch. | +| `git checkout -b ` | Create and checkout a branch. | +| `git branch -d ` | Delete a branch. | ## Docker {#cheat-docker} -### Docker CLI Commands - -+----+-------------------+-------------------+-------------------------+ -| S | Command | **What it does** | **Notes and helpful | -| ta | | | options** | -| ge | | | | -+----+-------------------+-------------------+-------------------------+ -| B | `docker b | Builds a | `-t ` | -| ui | uild ` | directory into an | provides a name to the | -| ld | | image. | container. | -| | | | | -| | | | `tag` is optional, | -| | | | defaults to `latest`. | -+----+-------------------+-------------------+-------------------------+ -| Mo | `doc | Push a container | | -| ve | ker push ` | to a registry. | | -+----+-------------------+-------------------+-------------------------+ -| Mo | `doc | Pull a container | Rarely needed because | -| ve | ker pull ` | from a registry. | `run` pulls the | -| | | | container if needed. | -+----+-------------------+-------------------+-------------------------+ -| R | `do | Run a container. | See flags in next | -| un | cker run ` | | table. | -+----+-------------------+-------------------+-------------------------+ -| R | `docker | Stop a running | `docker kill` can be | -| un | stop ` | container. | used if `stop` fails. | -+----+-------------------+-------------------+-------------------------+ -| R | `docker ps` | List running | Useful to get container | -| un | | containers. | `id` to do things to | -| | | | it. | -+----+-------------------+-------------------+-------------------------+ -| R | ` | Run a command | Basically always used | -| un | docker exec ` | container. | `docker exec -it | -| | | | /bin/bash` | -+----+-------------------+-------------------+-------------------------+ -| R | `docker | Views logs for a | | -| un | logs ` | container. | | -+----+-------------------+-------------------+-------------------------+ +### Docker CLI commands + + ++++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Stage

Command

What it does

Notes and helpful options

Build

docker build <directory>

Builds a directory into an image.

-t <name:tag> provides a name to the +container.

+

tag is optional, defaults to +latest.

Move

docker push <image>

Push a container to a registry.

Move

docker pull <image>

Pull a container from a registry.

Rarely needed because run pulls the container if +needed.

Run

docker run <image>

Run a container.

See flags in next table.

Run

docker stop <container>

Stop a running container.

docker kill can be used if stop +fails.

Run

docker ps

List running containers.

Useful to get container id to do things to +it.

Run

docker exec <cont aine r> <command>

Run a command inside a running container.

Basically always used to open a shell with +d ocker exec -it <co ntainer> /bin/bash

Run

docker logs <container>

Views logs for a container.

### Flags for `docker run` -+-------------+-------------+------------------------+ -| Flag | Effect | Notes | -+-------------+-------------+------------------------+ -| | Give a name | Optional. | -| `--n | to | Auto-assigned if not | -| ame ` | container. | provided | -+-------------+-------------+------------------------+ -| `--rm` | Remove | Don't use in | -| | container | production. You | -| | when its | probably want to | -| | stopped. | inspect failed | -| | | containers. | -+-------------+-------------+------------------------+ -| `-d` | Detach | Almost always used in | -| | container | production. | -| | (don't | | -| | block the | | -| | terminal). | | -+-------------+-------------+------------------------+ -| `-p :` | port from | access an app or API | -| | inside | inside the container. | -| | running | | -| | inside | | -| | container | | -| | to outside. | | -+-------------+-------------+------------------------+ -| `-v< | Mount | | -| dir>:` | volume into | | -| | the | | -| | container. | | -+-------------+-------------+------------------------+ +| | | | +|-----------------------|-----------------------|---------------------------| +| Flag | Effect | Notes | +| `--name ` | Give a name to container. | Optional. Auto-assigned if not provided | +| `--rm` | Remove container when its stopped. | Don't use in production. You probably want to inspect failed containers. | +| `-d` | Detach container (don't block the terminal). | Almost always used in production. | +| `-p :` | Publish port from inside running container to outside. | Needed if you want to access an app or API inside the container. | +| `-v :` | Mount volume into the container. | | *Reminder: Order for `-p` and `-v` is `:`* -### Dockerfile Commands +### Dockerfile commands These are the commands that go in a Dockerfile when you're building it. -+---------------+------------------------+----------------------------+ -| Command | Purpose | Example | -+---------------+------------------------+----------------------------+ -| `FROM` | Indicate base | `FROM rocker/r-ver:4.1.0` | -| | container. | | -+---------------+------------------------+----------------------------+ -| `RUN` | Run a command when | `RUN apt-get update` | -| | building. | | -+---------------+------------------------+----------------------------+ -| `COPY` | Copy from build | `COPY . /app/` | -| | directory into the | | -| | container. | | -+---------------+------------------------+----------------------------+ -| `CMD` | Specify the command to | `CMD quarto render .` | -| | run when the container | | -| | starts. | | -+---------------+------------------------+----------------------------+ - -## Cloud Services - -+---------------+---------------+------------+------------+ -| **Service** | **AWS** | **Azure** | **GCP** | -+---------------+---------------+------------+------------+ -| Kubernetes | EKS or | AKS | GKE | -| cluster | Fargate | | | -+---------------+---------------+------------+------------+ -| Run a | ECS or | Azure | Google App | -| container or | Elastic | Container | Engine | -| application | Beanstalk | Apps | | -+---------------+---------------+------------+------------+ -| Run an API | Lambda | Azure | Google | -| | | Functions | Cloud | -| | | | Functions | -+---------------+---------------+------------+------------+ -| Database | RDS | Azure SQL | Google | -| | | | Cloud | -| | | | Database | -+---------------+---------------+------------+------------+ -| Data | Redshift | DataLake | BigQuery | -| Warehouse | | | | -+---------------+---------------+------------+------------+ -| ML Platform | SageMaker | Azure ML | Vertex AI | -+---------------+---------------+------------+------------+ -| NAS | EFS or FSx | Azure File | Filestore | -+---------------+---------------+------------+------------+ - -## Command Line {#cheat-cli} - -### General Command Line - -| Symbol | What it is | -|-----------------|-----------------------------------| -| `man ` | Open manual for `command` | -| `q` | Quit the current screen | -| `\` | Continue bash command on new line | -| `ctrl + c` | Quit current execution | -| `echo ` | Print string (useful for piping) | - -### Linux Navigation - -+----------------+-----------------------+-----------------------+ -| Command | What it does/is | Notes + Helpful | -| | | options | -+================+=======================+=======================+ -| `/` | System root or file | | -| | path separator | | -+----------------+-----------------------+-----------------------+ -| `.` | current working | | -| | directory | | -+----------------+-----------------------+-----------------------+ -| `..` | Parent of working | | -| | directory | | -+----------------+-----------------------+-----------------------+ -| `~` | Home directory of the | | -| | current user | | -+----------------+-----------------------+-----------------------+ -| `ls ` | List objects in a | `-l` - format as list | -| | directory | | -| | | `-a` - all (include | -| | | hidden files that | -| | | start with `.`) | -+----------------+-----------------------+-----------------------+ -| `pwd` | Print working | | -| | directory | | -+----------------+-----------------------+-----------------------+ -| `cd ` | Change directory | Can use relative or | -| | | absolute paths | -+----------------+-----------------------+-----------------------+ - -### Reading Text Files - -+-----------------+-----------------+--------------------------+ -| **Command** | **What it | **Notes + Helpful | -| | does** | options** | -+-----------------+-----------------+--------------------------+ -| `cat ` | Print a file | | -| | from the top. | | -+-----------------+-----------------+--------------------------+ -| `less ` | Print a file, | Can be very helpful to | -| | but just a | look at a few rows of | -| | little. | csv. | -| | | | -| | | Lazily reads lines, so | -| | | can be *much* faster | -| | | than `cat` for big | -| | | files. | -+-----------------+-----------------+--------------------------+ -| `head ` | Look at the | Defaults to 10 lines, | -| | beginning of a | can specify a different | -| | file. | number with `-n `. | -+-----------------+-----------------+--------------------------+ -| `tail ` | Look at the end | Useful for logs where | -| | of a file. | the newest part is last. | -| | | | -| | | The `-f` flag is useful | -| | | to follow for a live | -| | | view. | -+-----------------+-----------------+--------------------------+ -| `gre | Search a file | Writing regex can be a | -| p ` | using regex. | pain. I suggest testing | -| | | on | -| | | $\text{regex101.com}$. | -| | | | -| | | Often useful in | -| | | combination with the | -| | | pipe. | -+-----------------+-----------------+--------------------------+ -| `|` | The pipe | | -+-----------------+-----------------+--------------------------+ -| `wc ` | Count words in | Use `-l` to count lines, | -| | a file | useful for `.csv` files. | -+-----------------+-----------------+--------------------------+ - -### Manipulating Files - -+----------------+-----------------+-------------------------+ -| **Command** | **What it | **Notes + Helpful | -| | does** | Options** | -+----------------+-----------------+-------------------------+ -| `rm ` | Remove | `-r` - recursively | -| | | remove everything below | -| | | a file path | -| | | | -| | | `-f` - force - don't | -| | | ask for each file | -| | | | -| | | **Be very careful, it's | -| | | permanent** | -+----------------+-----------------+-------------------------+ -| | | | -+----------------+-----------------+-------------------------+ -| `c | Copy | | -| p ` | | | -+----------------+-----------------+-------------------------+ -| `m | Move | | -| v ` | | | -+----------------+-----------------+-------------------------+ -| `*` | Wildcard | | -+----------------+-----------------+-------------------------+ -| ` | Make/remove | `-p` - create any parts | -| mkdir`/`rmdir` | directory | of path that don't | -| | | exist | -+----------------+-----------------+-------------------------+ +| | | | +|-------------------|-------------------------|-----------------------------| +| Command | Purpose | Example | +| `FROM` | Indicate base container. | `FROM rocker/r-ver:4.1.0` | +| `RUN` | Run a command when building. | `RUN apt-get update` | +| `COPY` | Copy from build directory into the container. | `COPY . /app/` | +| `CMD` | Specify the command to run when the container starts. | `CMD quarto render .` | + +## Cloud services + +| | | | | +|------------------|------------------|------------------|------------------| +| **Service** | **AWS** | **Azure** | **GCP** | +| Kubernetes cluster | EKS or Fargate | AKS | GKE | +| Run a container or application | ECS or Elastic Beanstalk | Azure Container Apps | Google App Engine | +| Run an API | Lambda | Azure Functions | Google Cloud Functions | +| Database | RDS | Azure SQL | Google Cloud Database | +| Data Warehouse | Redshift | DataLake | BigQuery | +| ML Platform | SageMaker | Azure ML | Vertex AI | +| NAS | EFS or FSx | Azure File | Filestore | + +## Command line {#cheat-cli} + +### General command line + +| Symbol | What it is | +|-----------------|------------------------------------| +| `man ` | Open manual for `command`. | +| `q` | Quit the current screen. | +| `\` | Continue bash command on new line. | +| `ctrl + c` | Quit current execution. | +| `echo ` | Print string (useful for piping). | + +### Linux filesystem navigation + + +++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Command

What it does/is

Notes + Helpful options

/

System root or file path separator.

.

Current working directory.

..

Parent of working directory.

~

Home directory of the current user.

ls <dir>

List objects in a directory.

-l - format as list

+

-a - all (include hidden files that start with +.)

pwd

Print working directory.

cd <dir>

Change directory.

Can use relative or absolute paths.

+ +### Reading text files + + +++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Command

What it does

Notes + Helpful options

cat <file>

Print a file from the top.

less <file>

Print a file, but just a little.

Can be very helpful to look at a few rows of csv.

+

Lazily reads lines, so can be much faster than +cat for big files.

head <file>

Look at the beginning of a file.

Defaults to 10 lines, can specify a different number with +-n <n>.

tail <file>

Look at the end of a file.

Useful for logs where the newest part is last.

+

The -f flag is useful to follow for a live +view.

grep <expression>

Search a file using regex.

Writing regex can be a pain. I suggest testing on .

+

Often useful in combination with the pipe.

|

The pipe.

wc <file>

Count words in a file.

Use -l to count lines, useful for .csv +files.

+ +### Manipulating files + + +++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Command

What it does

Notes + Helpful Options

rm <path>

Remove.

-r - recursively remove everything below a file +path

+

-f - force - dont ask for each file

+

Be very careful, its permanent!

cp <from> <to>

Copy.

mv <from> <to>

Move.

*

Wildcard.

mkdir/rmdir

Make/remove directory.

-p - create any parts of path that dont +exist

### Move things to/from server -+---------------+-----------------+-------------------------+ -| **Command** | **What it | **Notes + Helpful | -| | does** | Options** | -+---------------+-----------------+-------------------------+ -| `tar` | Create/extract | Almost always used with | -| | archive file | flags. | -| | | | -| | | Create is usually | -| | | `tar -czf ` | -| | | | -| | | Extract is usually | -| | | `t | -| | | ar -xfv ` | -+---------------+-----------------+-------------------------+ -| `scp` | Secure copy via | Run on laptop to server | -| | `ssh` | | -| | | Can use most `ssh` | -| | | flags (like `-i` and | -| | | `-v`) | -+---------------+-----------------+-------------------------+ + +++++ + + + + + + + + + + + + + + + + + +

Command

What it does

Notes + Helpful Options

tar

Create/extract archive file.

Almost always used with flags.

+

Create is usually +tar -czf <archive name> <file(s)>

+

Extract is usually +tar -xfv <archive name>

scp

Secure copy via ssh.

Run on laptop to server.

+

Can use most ssh flags (like -i and +-v).

### Write files from the command line -+----------------+-------------------+------------------------------+ -| Command | What it does | Notes | -+================+===================+==============================+ -| `touch` | Creates file if | Updates last updated to | -| | doesn't already | current time if it does | -| | exist. | exist. | -+----------------+-------------------+------------------------------+ -| `>` | Overwrite file | Creates a new file if it | -| | contents | doesn't exist | -+----------------+-------------------+------------------------------+ -| `>>` | Concatenate to | Creates a new file if it | -| | end of file | doesn't exist | -+----------------+-------------------+------------------------------+ - -### Command Line Text Editors (Vim + Nano) - -+----------------+-------------------------+------------------------+ -| Command | What it does | Notes + Helpful | -| | | options | -+================+=========================+========================+ -| `^` | Prefix for file command | Its the `⌘` or `Ctrl` | -| | in `nano` editor. | key, not the caret | -| | | symbol. | -+----------------+-------------------------+------------------------+ -| `i` | Enter insert mode (able | | -| | to type) in `vim` | | -+----------------+-------------------------+------------------------+ -| `escape` | Enter normal mode | | -| | (navigation) in `vim`. | | -+----------------+-------------------------+------------------------+ -| `:w` | Write the current file | Can be combined to | -| | in `vim` (from normal | save and quit in one, | -| | mode) | `:wq` | -+----------------+-------------------------+------------------------+ -| `:q` | Quit `vim` (from normal | `:q!` quit without | -| | mode) | saving | -+----------------+-------------------------+------------------------+ - -## `ssh` {#cheat-ssh} +| Command | What it does | Notes | +|--------------------|---------------------|-------------------------------| +| `touch` | Creates file if doesn't already exist. | Updates last updated to current time if it does exist. | +| `>` | Overwrite file contents. | Creates a new file if it doesn't exist. | +| `>>` | Concatenate to end of file. | Creates a new file if it doesn't exist. | + +### Command line text editors (Vim + Nano) + +| Command | What it does | Notes + Helpful options | +|--------------------|---------------------------|--------------------------| +| `^` | Prefix for file command in `nano` editor. | It's the `⌘` or `Ctrl` key, not the caret symbol. | +| `i` | Enter insert mode (able to type) in `vim`. | | +| `escape` | Enter normal mode (navigation) in `vim`. | | +| `:w` | Write the current file in `vim` (from normal mode). | Can be combined to save and quit in one, `:wq`. | +| `:q` | Quit `vim` (from normal mode). | `:q!` quit without saving. | + +## SSH {#cheat-ssh} + +General usage: ``` bash ssh @ ``` -+-----------------+---------------------+------------------------------+ -| Flag | What it does | Notes | -+=================+=====================+==============================+ -| `-v` | Verbose, good for | Add more `v`s as you please, | -| | debugging. | `-vv` or `-vvv`. | -+-----------------+---------------------+------------------------------+ -| `-i` | Choose identity | Not necessary with default | -| | file (private key) | key names. | -+-----------------+---------------------+------------------------------+ +| Flag | What it does | Notes | +|-------------------|----------------------|------------------------------| +| `-v` | Verbose, good for debugging. | Add more `v`s as you please, `-vv` or `-vvv`. | +| `-i` | Choose identity file (private key). | Not necessary with default key names. | -## Linux Admin +## Linux admin ### Users -+---------------+-----------------------------+------------------+ -| **Command** | **What it does** | **Helpful | -| | | options + | -| | | notes** | -+---------------+-----------------------------+------------------+ -| `s | Change to be a different | | -| u ` | user. | | -+---------------+-----------------------------+------------------+ -| `whoami` | Get username of current | | -| | user. | | -+---------------+-----------------------------+------------------+ -| `id` | Get full user + group info | | -| | on current user. | | -+---------------+-----------------------------+------------------+ -| `passwd` | Change password. | | -+---------------+-----------------------------+------------------+ -| `useradd` | Add a new user. | | -+---------------+-----------------------------+------------------+ -| `usermo | Modify user `username` | `-aG ` | -| d ` | | adds to a group | -| | | (e.g. `sudo`) | -+---------------+-----------------------------+------------------+ +| | | | +|--------------------|--------------------------------|--------------------| +| **Command** | **What it does** | **Helpful options + notes** | +| `su ` | Change to be a different user. | | +| `whoami` | Get username of current user. | | +| `id` | Get full user + group info on current user. | | +| `passwd` | Change password. | | +| `useradd` | Add a new user. | | +| `usermo d ` | Modify user `username`. | `-aG ` adds to a group (e.g.,`sudo`) | ### Permissions -+------------------------+--------------------+------------------------+ -| Command | What it does | Helpful options + | -| | | notes | -+========================+====================+========================+ -| `chmod | Modifies | Number indicates | -| ` | permissions on a | permissions for user, | -| | file or directory. | group, others: add `4` | -| | | for read, `2` for | -| | | write, `1` for | -| | | execute, `0` for | -| | | nothing, e.g. `644`. | -+------------------------+--------------------+------------------------+ -| `chow | Change the owner | Can be used for user | -| n ` | of a file or | or group, e.g. | -| | directory. | `:my-group`. | -+------------------------+--------------------+------------------------+ -| `sudo ` | Adopt root | | -| | permissions for | | -| | the following | | -| | command. | | -+------------------------+--------------------+------------------------+ +| Command | What it does | Helpful options + notes | +|-------------------------|---------------------|-------------------------| +| `chmod ` | Modifies permissions on a file or directory. | Number indicates permissions for user, group, others: add `4` for read, `2` for write, `1` for execute, `0` for nothing, e.g.,`644`. | +| `chown ` | Change the owner of a file or directory. | Can be used for user or group, e.g.,`:my-group`. | +| `sudo ` | Adopt root permissions for the following command. | | ### Install applications (Ubuntu) -+------------------------------+-------------------------+ -| **Command** | **What it does** | -+------------------------------+-------------------------+ -| `apt-get u | Fetch and install | -| pdate && apt-get upgrade -y` | upgrades to system | -| | packages | -+------------------------------+-------------------------+ -| `apt-get install ` | Install a system | -| | package. | -+------------------------------+-------------------------+ -| `wget` | Download a file from a | -| | URL. | -+------------------------------+-------------------------+ -| `gdebi` | Install local `.deb` | -| | file. | -+------------------------------+-------------------------+ +| | | +|---------------------------------------|---------------------------------| +| **Command** | **What it does** | +| `apt-get update && apt-get upgrade -y` | Fetch and install upgrades to system packages | +| `apt-get install ` | Install a system package. | +| `wget` | Download a file from a URL. | +| `gdebi` | Install local `.deb` file. | ### Storage -+----------------+----------------------+----------------------+ -| Command | What it does | Helpful options | -+================+======================+======================+ -| `df` | Check storage space | `-h` for human | -| | on device. | readable file sizes. | -+----------------+----------------------+----------------------+ -| `du` | Check size of files. | Most likely to be | -| | | used as | -| | | `d u | -| | | - h | sort -h` | -| | | | -| | | Also useful to | -| | | combine with `head`. | -+----------------+----------------------+----------------------+ + +++++ + + + + + + + + + + + + + + + + + + + +

Command

What it does

Helpful options

df

Check storage space on device.

-h for human readable file sizes.

du

Check size of files.

Most likely to be used as +du -h <dir> | sort -h

+

Also useful to combine with head.

### Processes -+----------------+-----------------+--------------------------------+ -| Command | What it does | Helpful options | -+================+=================+================================+ -| `top` | See what's | | -| | running on the | | -| | system. | | -+----------------+-----------------+--------------------------------+ -| `ps aux` | See all system | Consider using `--sort` and | -| | processes. | pipe into `head` or `grep` | -+----------------+-----------------+--------------------------------+ -| `kill` | Kill a system | `-9` to force kill immediately | -| | process. | | -+----------------+-----------------+--------------------------------+ +| Command | What it does | Helpful options | +|--------------------|--------------------|---------------------------------| +| `top` | See what's running on the system. | | +| `ps aux` | See all system processes. | Consider using `--sort` and pipe into `head` or `grep`. | +| `kill` | Kill a system process. | `-9` to force kill immediately | ### Networking -+-------------------+--------------+------------------------------+ -| **Command** | **What it | **Helpful Options** | -| | does** | | -+-------------------+--------------+------------------------------+ -| `netstat` | See ports | Usually used with `-tlp`, | -| | and services | for tcp listening | -| | using them. | applications, including | -| | | `pid` | -+-------------------+--------------+------------------------------+ -| `ssh -L :::` | forwards a | `localhost`. | -| | remote port | | -| | on remote | Choose local port to match | -| | host to | remote port. | -| | local. | | -+-------------------+--------------+------------------------------+ + +++++ + + + + + + + + + + + + + + + + + +

Command

What it does

Helpful Options

netstat

See ports and services using them.

Usually used with -tlp, for tcp listening +applications, including pid.

ssh -L <port>:<i p>:<port>:<host>

Port forwards a remote port on remote host to local.

Remote ip is usually localhost.

+

Choose local port to match remote port.

### The path -+-----------------------------+------------------------------+ -| **Command** | **What it does** | -+-----------------------------+------------------------------+ -| `which ` | Finds the location of the | -| | binary that runs when you | -| | run `command`. | -+-----------------------------+------------------------------+ -| `ln -s :` | at `location to link` to | -| | `location of symlink`. | -+-----------------------------+------------------------------+ +| | | +|-----------------------------------|------------------------------------| +| **Command** | **What it does** | +| `which ` | Finds the location of the binary that runs when you run `command`. | +| `ln -s :` | Creates a symlink from file/directory at `linked location` to `where to put symlink`. | ### `systemd` @@ -613,50 +596,51 @@ Daemonizing services is accomplished by configuring them in The format of all commands is `systemctl `. -+------------------------------------------+--------------------------+ -| Command | Notes/Tips | -+==========================================+==========================+ -| `status` | Report status | -+------------------------------------------+--------------------------+ -| `start` | | -+------------------------------------------+--------------------------+ -| `stop` | | -+------------------------------------------+--------------------------+ -| `restart` | `stop` then `start` | -+------------------------------------------+--------------------------+ -| `reload` | Reload configuration | -| | that doesn't require | -| | restart (depends on | -| | service) | -+------------------------------------------+--------------------------+ -| `enable` | Daemonize the service | -+------------------------------------------+--------------------------+ -| `disable` | Un-daemonize the service | -+------------------------------------------+--------------------------+ - -## IP Addresses and Ports {#cheat-ports} +| Command | Notes/Tips | +|-------------------|----------------------------| +| `status` | Report status. | +| `start` | | +| `stop` | | +| `restart` | `stop` then `start`. | +| `reload` | Reload configuration that doesn't require restart (depends on service). | +| `enable` | Daemonize the service. | +| `disable` | Un-daemonize the service. | + +## IP Addresses and ports {#cheat-ports} ### Special IP Addresses -+------------------------+--------------------------------------------+ -| Address | Meaning | -+========================+============================================+ -| $\text{127.0.0.1}$ | $\text{localhost}$ or loopback -- the | -| | machine that originated the request. | -+------------------------+--------------------------------------------+ -| $\text{192.168.x.x}$ | Protected address blocks used for private | -| | IP addresses. | -| $\text{172.16.x.x.x}$ | | -| | | -| $\text{10.x.x.x}$ | | -+------------------------+--------------------------------------------+ - -### Special Ports + ++++ + + + + + + + + + + + + + + + + +

Address

Meaning

or loopback – the machine that originated the request.

+

+

Protected address blocks used for private IP addresses.

+ +### Special ports All ports below $1024$ are reserved for server tasks and cannot be assigned to admin-controlled services. -| Protocol/Application | Default Port | +| Protocol/application | Default port | |----------------------|--------------| | HTTP | $80$ | | HTTPS | $443$ |