DevCheats logo

DevCheats

Clone a repository

Git
git clone <repo-url>

Shallow clone (depth 1)

Git
git clone --depth 1 <repo-url>

Clone specific branch

Git
git clone -b <branch> <repo-url>

Initialize a repo

Git
git init

Check status

Git
git status

Short status

Git
git status -s

Stage all changes

Git
git add .

Stage specific file

Git
git add <file>

Stage interactively

Git
git add -p

Commit with message

Git
git commit -m "message"

Amend last commit

Git
git commit --amend -m "new message"

Amend without editing msg

Git
git commit --amend --no-edit

Commit all tracked changes

Git
git commit -am "message"

Empty commit

Git
git commit --allow-empty -m "trigger CI"

Push to remote

Git
git push origin <branch>

Force push

Git
git push --force-with-lease

Push and set upstream

Git
git push -u origin <branch>

Push all branches

Git
git push --all

Pull latest changes

Git
git pull

Pull with rebase

Git
git pull --rebase

Pull specific branch

Git
git pull origin <branch>

Fetch all remotes

Git
git fetch --all

Fetch and prune

Git
git fetch --prune

Create a new branch

Git
git checkout -b <branch>

Switch branch

Git
git checkout <branch>

Switch branch (new syntax)

Git
git switch <branch>

Create & switch (new syntax)

Git
git switch -c <branch>

List all branches

Git
git branch -a

List merged branches

Git
git branch --merged

Delete a branch

Git
git branch -d <branch>

Force delete branch

Git
git branch -D <branch>

Delete remote branch

Git
git push origin --delete <branch>

Rename current branch

Git
git branch -m <new-name>

Merge a branch

Git
git merge <branch>

Merge no fast-forward

Git
git merge --no-ff <branch>

Abort a merge

Git
git merge --abort

Merge squash

Git
git merge --squash <branch>

Rebase onto branch

Git
git rebase <branch>

Interactive rebase

Git
git rebase -i HEAD~<n>

Abort rebase

Git
git rebase --abort

Continue rebase

Git
git rebase --continue

Rebase onto

Git
git rebase --onto <new> <old> <branch>

Stash changes

Git
git stash

Stash with message

Git
git stash push -m "message"

Stash including untracked

Git
git stash -u

Apply stash

Git
git stash pop

List stashes

Git
git stash list

Apply specific stash

Git
git stash apply stash@{n}

Drop a stash

Git
git stash drop stash@{n}

Clear all stashes

Git
git stash clear

View commit log

Git
git log --oneline

Log with graph

Git
git log --oneline --graph --all

Log last N commits

Git
git log -n <number>

Log by author

Git
git log --author="name"

Log since date

Git
git log --since="2024-01-01"

Log file changes

Git
git log --follow -p <file>

Show a commit

Git
git show <commit>

Show files in commit

Git
git show --stat <commit>

Reset to last commit (hard)

Git
git reset --hard HEAD

Reset to last commit (soft)

Git
git reset --soft HEAD~1

Reset to commit (mixed)

Git
git reset HEAD~1

Unstage a file

Git
git reset HEAD <file>

Restore file (new syntax)

Git
git restore <file>

Unstage (new syntax)

Git
git restore --staged <file>

Revert a commit

Git
git revert <commit>

Cherry-pick a commit

Git
git cherry-pick <commit>

Cherry-pick no commit

Git
git cherry-pick -n <commit>

View diff

Git
git diff

Diff staged changes

Git
git diff --staged

Diff between branches

Git
git diff <branch1>..<branch2>

Diff stat only

Git
git diff --stat

Diff word-level

Git
git diff --word-diff

Blame a file

Git
git blame <file>

Create a tag

Git
git tag <tagname>

Create annotated tag

Git
git tag -a v1.0 -m "message"

Push tags

Git
git push --tags

Delete a tag

Git
git tag -d <tagname>

Delete remote tag

Git
git push origin :refs/tags/<tag>

List tags

Git
git tag -l

List remotes

Git
git remote -v

Add a remote

Git
git remote add <name> <url>

Remove a remote

Git
git remote remove <name>

Change remote URL

Git
git remote set-url origin <url>

Clean untracked files

Git
git clean -fd

Dry run clean

Git
git clean -fdn

Bisect start

Git
git bisect start

Bisect good/bad

Git
git bisect good / git bisect bad

Bisect reset

Git
git bisect reset

Reflog

Git
git reflog

Worktree add

Git
git worktree add <path> <branch>

Worktree list

Git
git worktree list

Submodule add

Git
git submodule add <url>

Submodule update

Git
git submodule update --init --recursive

Submodule status

Git
git submodule status

Config user name

Git
git config --global user.name "Name"

Config user email

Git
git config --global user.email "email"

List config

Git
git config --list

Set default branch

Git
git config --global init.defaultBranch main

Enable auto-correct

Git
git config --global help.autocorrect 1

Global gitignore

Git
git config --global core.excludesfile ~/.gitignore_global

Show short SHA

Git
git rev-parse --short HEAD

Count commits

Git
git rev-list --count HEAD

Archive a branch

Git
git archive --format=zip HEAD > archive.zip

Find commit by message

Git
git log --grep="keyword"

List files in commit

Git
git diff-tree --no-commit-id --name-only -r <commit>

Show who changed file

Git
git shortlog -sn -- <file>

List files

Terminal
ls -la

List files (human sizes)

Terminal
ls -lah

List sorted by time

Terminal
ls -lt

List sorted by size

Terminal
ls -lS

Tree view

Terminal
tree -L 2

Tree (dirs only)

Terminal
tree -d -L 3

Change directory

Terminal
cd <path>

Go to home

Terminal
cd ~

Go back

Terminal
cd -

Print working directory

Terminal
pwd

Create a directory

Terminal
mkdir -p <dir>

Create a file

Terminal
touch <file>

Remove a file

Terminal
rm <file>

Remove directory recursively

Terminal
rm -rf <dir>

Copy files

Terminal
cp <src> <dest>

Copy directory

Terminal
cp -r <src> <dest>

Move/rename files

Terminal
mv <src> <dest>

View file contents

Terminal
cat <file>

Concatenate files

Terminal
cat file1 file2 > combined

Number lines

Terminal
cat -n <file>

View with pager

Terminal
less <file>

First N lines

Terminal
head -n 20 <file>

Last N lines

Terminal
tail -n 20 <file>

Follow log output

Terminal
tail -f <file>

Word count

Terminal
wc -l <file>

Search in files

Terminal
grep -r "pattern" <dir>

Search case-insensitive

Terminal
grep -ri "pattern" <dir>

Search with line numbers

Terminal
grep -rn "pattern" .

Grep with context

Terminal
grep -C 3 "pattern" <file>

Grep exclude dir

Terminal
grep -r --exclude-dir=node_modules "pattern" .

Ripgrep search

Terminal
rg "pattern" --type ts

Find files by name

Terminal
find . -name "*.ext"

Find files by type

Terminal
find . -type f -name '*.log'

Find and delete

Terminal
find . -name '*.tmp' -delete

Find large files

Terminal
find . -size +100M

Find modified recently

Terminal
find . -mmin -60 -type f

Find and exec

Terminal
find . -name '*.js' -exec wc -l {} +

fd (find alternative)

Terminal
fd -e ts -e tsx

Download a file (curl)

Terminal
curl -O <url>

Download a file (wget)

Terminal
wget <url>

Curl with headers

Terminal
curl -H 'Authorization: Bearer <token>' <url>

POST JSON with curl

Terminal
curl -X POST -H 'Content-Type: application/json' -d '{"key":"val"}' <url>

Curl follow redirects

Terminal
curl -L <url>

Curl verbose

Terminal
curl -v <url>

Curl save to file

Terminal
curl -o output.txt <url>

SSH into server

Terminal
ssh user@host

SSH with key

Terminal
ssh -i key.pem user@host

SSH tunnel

Terminal
ssh -L 8080:localhost:80 user@host

SSH reverse tunnel

Terminal
ssh -R 9090:localhost:3000 user@host

SCP file to remote

Terminal
scp file user@host:/path

SCP from remote

Terminal
scp user@host:/path/file .

Rsync sync dirs

Terminal
rsync -avz src/ user@host:/dest/

Rsync dry run

Terminal
rsync -avzn src/ dest/

Change permissions

Terminal
chmod 755 <file>

Change owner

Terminal
chown user:group <file>

Make executable

Terminal
chmod +x <file>

Recursive permissions

Terminal
chmod -R 644 <dir>

Create tar archive

Terminal
tar -czf archive.tar.gz <dir>

Extract tar archive

Terminal
tar -xzf archive.tar.gz

List tar contents

Terminal
tar -tzf archive.tar.gz

Create zip

Terminal
zip -r archive.zip <dir>

Extract zip

Terminal
unzip archive.zip

Disk usage

Terminal
du -sh <dir>

Disk usage sorted

Terminal
du -sh */ | sort -rh

Disk free space

Terminal
df -h

Memory usage

Terminal
free -h

System info

Terminal
uname -a

OS release info

Terminal
cat /etc/os-release

CPU info

Terminal
lscpu

Top processes

Terminal
top

Better top (htop)

Terminal
htop

Bottom (btm)

Terminal
btm

Kill a process

Terminal
kill -9 <pid>

Kill by name

Terminal
killall <name>

Find process by port

Terminal
lsof -i :<port>

Find process by name

Terminal
ps aux | grep <name>

Watch command

Terminal
watch -n 1 <command>

Run in background

Terminal
<command> &

Nohup background

Terminal
nohup <command> &

Jobs list

Terminal
jobs

Bring to foreground

Terminal
fg %1

Redirect stdout to file

Terminal
<command> > output.txt

Append to file

Terminal
<command> >> output.txt

Redirect stderr

Terminal
<command> 2> errors.txt

Redirect all output

Terminal
<command> &> all.txt

Pipe output

Terminal
<cmd1> | <cmd2>

Tee (pipe + file)

Terminal
<command> | tee output.txt

Command history

Terminal
history

Search history

Terminal
history | grep <term>

Reverse search

Terminal
Ctrl+R

Clear history

Terminal
history -c

Run last command

Terminal
!!

Run by history number

Terminal
!<number>

Set environment variable

Terminal
export VAR=value

Print env variable

Terminal
echo $VAR

All env variables

Terminal
env

Unset variable

Terminal
unset VAR

Source a file

Terminal
source ~/.bashrc

Alias a command

Terminal
alias ll='ls -la'

Which binary

Terminal
which <command>

Type of command

Terminal
type <command>

Check open ports

Terminal
netstat -tlnp

SS (modern netstat)

Terminal
ss -tlnp

DNS lookup

Terminal
nslookup <domain>

Dig DNS query

Terminal
dig <domain>

Ping a host

Terminal
ping -c 4 <host>

Trace route

Terminal
traceroute <host>

Public IP

Terminal
curl ifconfig.me

Local IP

Terminal
hostname -I

Sed replace in file

Terminal
sed -i 's/old/new/g' <file>

Sed delete lines

Terminal
sed -i '1,5d' <file>

Awk print column

Terminal
awk '{print $1}' <file>

Awk with delimiter

Terminal
awk -F: '{print $1}' /etc/passwd

Cut columns

Terminal
cut -d',' -f1,3 <file>

Sort output

Terminal
sort <file>

Sort numeric

Terminal
sort -n <file>

Unique lines

Terminal
sort <file> | uniq

Count occurrences

Terminal
sort <file> | uniq -c | sort -rn

xargs from stdin

Terminal
echo 'a b c' | xargs -n1

Parallel xargs

Terminal
cat files.txt | xargs -P 4 -I {} cmd {}

Symlink

Terminal
ln -s <target> <link>

Current date/time

Terminal
date

Date formatted

Terminal
date +%Y-%m-%d_%H%M%S

Calendar

Terminal
cal

Epoch timestamp

Terminal
date +%s

Generate SSH key

Terminal
ssh-keygen -t ed25519 -C "email"

Add SSH key to agent

Terminal
ssh-add ~/.ssh/id_ed25519

Check checksum

Terminal
sha256sum <file>

MD5 checksum

Terminal
md5sum <file>

Base64 encode

Terminal
echo -n 'text' | base64

Base64 decode

Terminal
echo 'encoded' | base64 -d

Generate random string

Terminal
openssl rand -hex 32

Generate UUID

Terminal
uuidgen

JSON pretty print (jq)

Terminal
cat data.json | jq .

jq filter

Terminal
cat data.json | jq '.key'

Crontab edit

Terminal
crontab -e

Crontab list

Terminal
crontab -l

Systemd service status

Terminal
systemctl status <service>

Systemd restart

Terminal
sudo systemctl restart <service>

Systemd enable on boot

Terminal
sudo systemctl enable <service>

Systemd logs

Terminal
journalctl -u <service> -f

Screen new session

Terminal
screen -S <name>

Tmux new session

Terminal
tmux new -s <name>

Tmux attach

Terminal
tmux attach -t <name>

Tmux list sessions

Terminal
tmux ls

Tmux split vertical

Terminal
Ctrl+B %

Tmux split horizontal

Terminal
Ctrl+B "

Diff two files

Terminal
diff <file1> <file2>

Side-by-side diff

Terminal
diff -y <file1> <file2>

Colored diff

Terminal
colordiff <file1> <file2>

File type info

Terminal
file <file>

Stat file details

Terminal
stat <file>

Who is logged in

Terminal
who

Uptime

Terminal
uptime

Hex dump

Terminal
xxd <file> | head

Initialize project

npm/yarn
npm init -y

Install all deps

npm/yarn
npm install

Add a package

npm/yarn
npm install <package>

Add dev dependency

npm/yarn
npm install -D <package>

Add global package

npm/yarn
npm install -g <package>

Add exact version

npm/yarn
npm install <package>@1.2.3

Remove a package

npm/yarn
npm uninstall <package>

Run a script

npm/yarn
npm run <script>

Start dev server

npm/yarn
npm run dev

Build for production

npm/yarn
npm run build

Run tests

npm/yarn
npm test

Run tests in watch

npm/yarn
npm test -- --watch

Update all packages

npm/yarn
npm update

Check outdated

npm/yarn
npm outdated

Audit vulnerabilities

npm/yarn
npm audit

Fix audit issues

npm/yarn
npm audit fix

List installed

npm/yarn
npm list --depth=0

List global packages

npm/yarn
npm list -g --depth=0

View package info

npm/yarn
npm info <package>

View package versions

npm/yarn
npm view <package> versions

Cache clean

npm/yarn
npm cache clean --force

Run with npx

npm/yarn
npx <package>

npx with version

npm/yarn
npx <package>@latest

Create React app (Vite)

npm/yarn
npm create vite@latest my-app

Create Next.js app

npm/yarn
npx create-next-app@latest

Create Astro project

npm/yarn
npm create astro@latest

Create SvelteKit

npm/yarn
npm create svelte@latest my-app

Create Remix app

npm/yarn
npx create-remix@latest

Create Nuxt app

npm/yarn
npx nuxi init my-app

Create T3 Stack

npm/yarn
npm create t3-app@latest

Publish to npm

npm/yarn
npm publish

Publish dry run

npm/yarn
npm publish --dry-run

Login to npm

npm/yarn
npm login

Whoami npm

npm/yarn
npm whoami

Link local package

npm/yarn
npm link

Unlink package

npm/yarn
npm unlink <package>

Pack preview

npm/yarn
npm pack

Bump patch version

npm/yarn
npm version patch

Bump minor version

npm/yarn
npm version minor

Bump major version

npm/yarn
npm version major

npm ci (clean install)

npm/yarn
npm ci

Deduplicate deps

npm/yarn
npm dedupe

Why is pkg installed

npm/yarn
npm explain <package>

Yarn add

npm/yarn
yarn add <package>

Yarn add dev

npm/yarn
yarn add -D <package>

Yarn remove

npm/yarn
yarn remove <package>

Yarn install

npm/yarn
yarn install

Yarn upgrade

npm/yarn
yarn upgrade

Yarn upgrade interactive

npm/yarn
yarn upgrade-interactive

Yarn why

npm/yarn
yarn why <package>

pnpm install

npm/yarn
pnpm install

pnpm add

npm/yarn
pnpm add <package>

pnpm add dev

npm/yarn
pnpm add -D <package>

pnpm remove

npm/yarn
pnpm remove <package>

pnpm store prune

npm/yarn
pnpm store prune

pnpm why

npm/yarn
pnpm why <package>

Bun install

npm/yarn
bun install

Bun add

npm/yarn
bun add <package>

Bun add dev

npm/yarn
bun add -D <package>

Bun run

npm/yarn
bun run <script>

Bun create

npm/yarn
bun create <template>

Bun test

npm/yarn
bun test

Bun build

npm/yarn
bun build ./src/index.ts --outdir ./dist

Check Node version

npm/yarn
node -v

Check npm version

npm/yarn
npm -v

Use nvm to switch Node

npm/yarn
nvm use <version>

Install Node via nvm

npm/yarn
nvm install <version>

List nvm versions

npm/yarn
nvm ls

Set default nvm

npm/yarn
nvm alias default <version>

Volta install Node

npm/yarn
volta install node@<version>

Volta pin

npm/yarn
volta pin node@<version>

npm init with scope

npm/yarn
npm init --scope=@org

npm config set registry

npm/yarn
npm config set registry <url>

Build an image

Docker
docker build -t <name> .

Build with no cache

Docker
docker build --no-cache -t <name> .

Build with build args

Docker
docker build --build-arg KEY=val -t <name> .

Build multi-stage

Docker
docker build --target production -t <name> .

Build for platform

Docker
docker build --platform linux/amd64 -t <name> .

Buildx multi-arch

Docker
docker buildx build --platform linux/amd64,linux/arm64 -t <name> --push .

Run a container

Docker
docker run -d -p 3000:3000 <image>

Run interactive

Docker
docker run -it <image> bash

Run with env vars

Docker
docker run -e KEY=val <image>

Run with volume

Docker
docker run -v /host:/container <image>

Run with name

Docker
docker run --name <name> <image>

Run with auto-remove

Docker
docker run --rm <image>

Run with env file

Docker
docker run --env-file .env <image>

Run with network

Docker
docker run --network <name> <image>

Run with memory limit

Docker
docker run -m 512m <image>

Run with CPU limit

Docker
docker run --cpus=2 <image>

Run with restart policy

Docker
docker run --restart unless-stopped <image>

List running containers

Docker
docker ps

List all containers

Docker
docker ps -a

List container IDs

Docker
docker ps -q

Stop a container

Docker
docker stop <id>

Stop all containers

Docker
docker stop $(docker ps -q)

Start a container

Docker
docker start <id>

Restart a container

Docker
docker restart <id>

Remove a container

Docker
docker rm <id>

Remove all stopped

Docker
docker container prune

Force remove container

Docker
docker rm -f <id>

List images

Docker
docker images

Remove an image

Docker
docker rmi <image>

Remove dangling images

Docker
docker image prune

Remove all images

Docker
docker rmi $(docker images -q)

Pull an image

Docker
docker pull <image>

Push an image

Docker
docker push <image>

Tag an image

Docker
docker tag <image> <repo>:<tag>

Image history

Docker
docker history <image>

Execute in container

Docker
docker exec -it <id> bash

Execute as root

Docker
docker exec -it -u root <id> bash

View container logs

Docker
docker logs <id>

Follow logs

Docker
docker logs -f <id>

Logs since time

Docker
docker logs --since 1h <id>

Logs with timestamps

Docker
docker logs -t <id>

Inspect container

Docker
docker inspect <id>

Inspect format IP

Docker
docker inspect -f '{{.NetworkSettings.IPAddress}}' <id>

Copy to container

Docker
docker cp file <id>:/path

Copy from container

Docker
docker cp <id>:/path file

View resource usage

Docker
docker stats

Container top processes

Docker
docker top <id>

Diff container changes

Docker
docker diff <id>

Commit container as image

Docker
docker commit <id> <new-image>

Wait for container exit

Docker
docker wait <id>

Rename container

Docker
docker rename <old> <new>

Compose up

Docker
docker compose up -d

Compose up with build

Docker
docker compose up -d --build

Compose up specific

Docker
docker compose up -d <service>

Compose down

Docker
docker compose down

Compose down + volumes

Docker
docker compose down -v

Compose down + images

Docker
docker compose down --rmi all

Compose logs

Docker
docker compose logs -f

Compose logs service

Docker
docker compose logs -f <service>

Compose ps

Docker
docker compose ps

Compose exec

Docker
docker compose exec <service> bash

Compose restart

Docker
docker compose restart <service>

Compose pull

Docker
docker compose pull

Compose build

Docker
docker compose build

Compose scale

Docker
docker compose up -d --scale <service>=3

Compose config validate

Docker
docker compose config

Compose top

Docker
docker compose top

List volumes

Docker
docker volume ls

Create volume

Docker
docker volume create <name>

Remove volume

Docker
docker volume rm <name>

Inspect volume

Docker
docker volume inspect <name>

List networks

Docker
docker network ls

Create network

Docker
docker network create <name>

Inspect network

Docker
docker network inspect <name>

Connect to network

Docker
docker network connect <net> <container>

Disconnect from network

Docker
docker network disconnect <net> <container>

Prune everything

Docker
docker system prune -a

Prune with volumes

Docker
docker system prune -a --volumes

Disk usage

Docker
docker system df

Disk usage verbose

Docker
docker system df -v

Login to registry

Docker
docker login

Login to custom registry

Docker
docker login <registry-url>

Save image to tar

Docker
docker save -o image.tar <image>

Load image from tar

Docker
docker load -i image.tar

Docker events

Docker
docker events

Docker version

Docker
docker version

Docker info

Docker
docker info

Install Ollama

AI
curl -fsSL https://ollama.com/install.sh | sh

Run a model (Ollama)

AI
ollama run llama3

Pull a model

AI
ollama pull mistral

List local models

AI
ollama list

Remove a model

AI
ollama rm <model>

Show model info

AI
ollama show llama3

Serve Ollama API

AI
ollama serve

Create custom model

AI
ollama create mymodel -f Modelfile

Copy a model

AI
ollama cp llama3 my-llama3

Ollama API generate

AI
curl http://localhost:11434/api/generate -d '{"model":"llama3","prompt":"hello"}'

Ollama API chat

AI
curl http://localhost:11434/api/chat -d '{"model":"llama3","messages":[{"role":"user","content":"hi"}]}'

Ollama pull with progress

AI
ollama pull codellama

Ollama run with system

AI
ollama run llama3 --system "You are helpful"

Ollama embeddings

AI
curl http://localhost:11434/api/embeddings -d '{"model":"llama3","prompt":"text"}'

Install OpenAI CLI

AI
pip install openai

Set OpenAI API key

AI
export OPENAI_API_KEY='sk-...'

Chat completion (curl)

AI
curl https://api.openai.com/v1/chat/completions -H 'Authorization: Bearer $OPENAI_API_KEY' -H 'Content-Type: application/json' -d '{"model":"gpt-4","messages":[{"role":"user","content":"hello"}]}'

List OpenAI models

AI
curl https://api.openai.com/v1/models -H 'Authorization: Bearer $OPENAI_API_KEY'

Generate embeddings

AI
curl https://api.openai.com/v1/embeddings -H 'Authorization: Bearer $OPENAI_API_KEY' -d '{"model":"text-embedding-3-small","input":"text"}'

OpenAI image generation

AI
curl https://api.openai.com/v1/images/generations -H 'Authorization: Bearer $OPENAI_API_KEY' -d '{"model":"dall-e-3","prompt":"a cat"}'

OpenAI TTS

AI
curl https://api.openai.com/v1/audio/speech -H 'Authorization: Bearer $OPENAI_API_KEY' -d '{"model":"tts-1","input":"Hello","voice":"alloy"}' --output speech.mp3

OpenAI Whisper

AI
curl https://api.openai.com/v1/audio/transcriptions -H 'Authorization: Bearer $OPENAI_API_KEY' -F file=@audio.mp3 -F model=whisper-1

Install Anthropic SDK

AI
pip install anthropic

Set Anthropic key

AI
export ANTHROPIC_API_KEY='sk-ant-...'

Claude API (curl)

AI
curl https://api.anthropic.com/v1/messages -H 'x-api-key: $ANTHROPIC_API_KEY' -H 'anthropic-version: 2023-06-01' -H 'Content-Type: application/json' -d '{"model":"claude-sonnet-4-20250514","max_tokens":1024,"messages":[{"role":"user","content":"hello"}]}'

Install HF CLI

AI
pip install huggingface_hub

Login to HF

AI
huggingface-cli login

Download HF model

AI
huggingface-cli download <model-id>

Upload to HF

AI
huggingface-cli upload <repo-id> <local-path>

HF model info

AI
huggingface-cli repo info <model-id>

List HF cache

AI
huggingface-cli scan-cache

Delete HF cache

AI
huggingface-cli delete-cache

Create HF repo

AI
huggingface-cli repo create <name> --type model

Install PyTorch

AI
pip install torch torchvision torchaudio

Install PyTorch (CUDA)

AI
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121

Install TensorFlow

AI
pip install tensorflow

Install Transformers

AI
pip install transformers

Install LangChain

AI
pip install langchain langchain-openai

Install LlamaIndex

AI
pip install llama-index

Install llama-cpp-python

AI
pip install llama-cpp-python

Install vLLM

AI
pip install vllm

Install Gradio

AI
pip install gradio

Install Streamlit

AI
pip install streamlit

Install LiteLLM

AI
pip install litellm

Install Sentence Transformers

AI
pip install sentence-transformers

Install FAISS

AI
pip install faiss-cpu

Install FAISS GPU

AI
pip install faiss-gpu

Install ChromaDB

AI
pip install chromadb

Install Pinecone

AI
pip install pinecone-client

Install Weaviate

AI
pip install weaviate-client

Install Qdrant

AI
pip install qdrant-client

Install spaCy

AI
pip install spacy

Download spaCy model

AI
python -m spacy download en_core_web_sm

Install scikit-learn

AI
pip install scikit-learn

Install pandas

AI
pip install pandas

Install matplotlib

AI
pip install matplotlib seaborn

Install OpenCV

AI
pip install opencv-python

Install Pillow

AI
pip install Pillow

Install datasets

AI
pip install datasets

Install accelerate

AI
pip install accelerate

Install PEFT (LoRA)

AI
pip install peft

Install bitsandbytes

AI
pip install bitsandbytes

Install trl (RLHF)

AI
pip install trl

Install unsloth

AI
pip install unsloth

Serve model with vLLM

AI
python -m vllm.entrypoints.openai.api_server --model <model>

vLLM with quantization

AI
python -m vllm.entrypoints.openai.api_server --model <model> --quantization awq

Run Gradio app

AI
python app.py  # gradio interface

Run Streamlit app

AI
streamlit run app.py

LiteLLM proxy

AI
litellm --model ollama/llama3 --port 8000

TGI (HF Inference)

AI
docker run --gpus all -p 8080:80 ghcr.io/huggingface/text-generation-inference --model-id <model>

Build llama.cpp

AI
cmake -B build && cmake --build build --config Release

Build llama.cpp CUDA

AI
cmake -B build -DGGML_CUDA=ON && cmake --build build --config Release

Run llama.cpp

AI
./build/bin/llama-cli -m model.gguf -p 'Hello' -n 128

Quantize model (llama.cpp)

AI
./build/bin/llama-quantize model.gguf model-q4.gguf Q4_K_M

llama.cpp server

AI
./build/bin/llama-server -m model.gguf --port 8080

Convert HF to GGUF

AI
python convert_hf_to_gguf.py <model-dir>

Check CUDA version

AI
nvcc --version

Check GPU (nvidia)

AI
nvidia-smi

Watch GPU usage

AI
watch -n 1 nvidia-smi

Python check PyTorch GPU

AI
python -c "import torch; print(torch.cuda.is_available())"

Check TF GPU

AI
python -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))"

Create venv for ML

AI
python -m venv .venv && source .venv/bin/activate

Conda create env

AI
conda create -n ml python=3.11 -y

Conda activate

AI
conda activate ml

Conda list envs

AI
conda env list

Conda install

AI
conda install <package>

Freeze requirements

AI
pip freeze > requirements.txt

Install from requirements

AI
pip install -r requirements.txt

UV pip install

AI
uv pip install <package>

UV venv create

AI
uv venv

Jupyter notebook

AI
jupyter notebook

JupyterLab

AI
jupyter lab

Install Jupyter

AI
pip install jupyterlab notebook

Weights & Biases login

AI
wandb login

Install W&B

AI
pip install wandb

MLflow UI

AI
mlflow ui --port 5000

Install MLflow

AI
pip install mlflow

Tensorboard

AI
tensorboard --logdir=./logs

Install Tensorboard

AI
pip install tensorboard

DVC init

AI
dvc init

DVC add data

AI
dvc add data/

DVC push

AI
dvc push

Install DVC

AI
pip install dvc

AWS configure credentials

Cloud & Deploy

Set access key, secret, region and output format.

aws configure

AWS configure named profile

Cloud & Deploy
aws configure --profile <name>

AWS whoami

Cloud & Deploy

Show the account and IAM identity in use.

aws sts get-caller-identity

List S3 buckets

Cloud & Deploy
aws s3 ls

List S3 bucket contents

Cloud & Deploy
aws s3 ls s3://<bucket>/<prefix>/

Copy file to S3

Cloud & Deploy
aws s3 cp ./<file> s3://<bucket>/<key>

Sync folder to S3

Cloud & Deploy

--delete removes remote files missing locally.

aws s3 sync ./dist s3://<bucket> --delete
Destructive

Presign S3 download URL

Cloud & Deploy
aws s3 presign s3://<bucket>/<key> --expires-in 3600

Delete S3 object

Cloud & Deploy
aws s3 rm s3://<bucket>/<key>
Destructive

Invalidate CloudFront cache

Cloud & Deploy
aws cloudfront create-invalidation --distribution-id <id> --paths "/*"

List EC2 instances

Cloud & Deploy
aws ec2 describe-instances --query "Reservations[].Instances[].[InstanceId,State.Name,PublicIpAddress]" --output table

Start EC2 instance

Cloud & Deploy
aws ec2 start-instances --instance-ids <id>

Stop EC2 instance

Cloud & Deploy
aws ec2 stop-instances --instance-ids <id>
Destructive

List Lambda functions

Cloud & Deploy
aws lambda list-functions --query "Functions[].FunctionName"

Invoke Lambda function

Cloud & Deploy
aws lambda invoke --function-name <name> --payload '{}' out.json

Tail Lambda logs

Cloud & Deploy
aws logs tail /aws/lambda/<name> --follow

Deploy Lambda zip

Cloud & Deploy
aws lambda update-function-code --function-name <name> --zip-file fileb://function.zip

Login to ECR

Cloud & Deploy
aws ecr get-login-password --region <region> | docker login --username AWS --password-stdin <acct>.dkr.ecr.<region>.amazonaws.com

Create ECR repository

Cloud & Deploy
aws ecr create-repository --repository-name <name>

List ECR images

Cloud & Deploy
aws ecr list-images --repository-name <name>

Deploy CloudFormation stack

Cloud & Deploy
aws cloudformation deploy --template-file template.yml --stack-name <name> --capabilities CAPABILITY_IAM

Delete CloudFormation stack

Cloud & Deploy
aws cloudformation delete-stack --stack-name <name>
Destructive

Read SSM parameter

Cloud & Deploy
aws ssm get-parameter --name <name> --with-decryption --query Parameter.Value --output text

Read Secrets Manager secret

Cloud & Deploy
aws secretsmanager get-secret-value --secret-id <id> --query SecretString --output text

gcloud login

Cloud & Deploy
gcloud auth login

gcloud set project

Cloud & Deploy
gcloud config set project <project-id>

List gcloud projects

Cloud & Deploy
gcloud projects list

Deploy to Cloud Run

Cloud & Deploy
gcloud run deploy <service> --source . --region <region> --allow-unauthenticated

List Cloud Run services

Cloud & Deploy
gcloud run services list

Tail Cloud Run logs

Cloud & Deploy
gcloud beta run services logs tail <service> --region <region>

Build with Cloud Build

Cloud & Deploy
gcloud builds submit --tag gcr.io/<project>/<image>

List GCS buckets

Cloud & Deploy
gsutil ls

Copy to GCS

Cloud & Deploy
gsutil cp ./<file> gs://<bucket>/

Sync folder to GCS

Cloud & Deploy
gsutil -m rsync -r ./dist gs://<bucket>

Configure docker for GCR

Cloud & Deploy
gcloud auth configure-docker

Azure login

Cloud & Deploy
az login

Set Azure subscription

Cloud & Deploy
az account set --subscription <id>

List Azure resource groups

Cloud & Deploy
az group list --output table

Deploy Azure web app

Cloud & Deploy
az webapp up --name <app> --runtime "NODE:20-lts"

Tail Azure web app logs

Cloud & Deploy
az webapp log tail --name <app> --resource-group <group>

Push to Azure container registry

Cloud & Deploy
az acr build --registry <registry> --image <image>:<tag> .

Deploy preview to Vercel

Cloud & Deploy
vercel

Deploy to Vercel production

Cloud & Deploy
vercel --prod

Link local dir to Vercel project

Cloud & Deploy
vercel link

Pull Vercel env vars

Cloud & Deploy
vercel env pull .env.local

Add Vercel env var

Cloud & Deploy
vercel env add <NAME> production

List Vercel deployments

Cloud & Deploy
vercel ls

Vercel deployment logs

Cloud & Deploy
vercel logs <deployment-url>

Rollback Vercel deployment

Cloud & Deploy
vercel rollback <deployment-url>

Deploy to Netlify

Cloud & Deploy
netlify deploy --prod --dir=dist

Netlify dev server

Cloud & Deploy
netlify dev

Link Netlify site

Cloud & Deploy
netlify link

Netlify function logs

Cloud & Deploy
netlify functions:log <name>

Launch a Fly.io app

Cloud & Deploy
fly launch

Deploy to Fly.io

Cloud & Deploy
fly deploy

Fly.io logs

Cloud & Deploy
fly logs

Fly.io SSH console

Cloud & Deploy
fly ssh console

Scale Fly.io machines

Cloud & Deploy
fly scale count 2

Set Fly.io secret

Cloud & Deploy
fly secrets set <NAME>=<value>

Deploy Cloudflare Worker

Cloud & Deploy
wrangler deploy

Cloudflare Worker dev server

Cloud & Deploy
wrangler dev

Tail Cloudflare Worker logs

Cloud & Deploy
wrangler tail

Set Cloudflare Worker secret

Cloud & Deploy
wrangler secret put <NAME>

Deploy Cloudflare Pages

Cloud & Deploy
wrangler pages deploy ./dist

Query Cloudflare D1

Cloud & Deploy
wrangler d1 execute <db> --command "SELECT 1"

Upload to R2

Cloud & Deploy
wrangler r2 object put <bucket>/<key> --file ./<file>

Create Heroku app

Cloud & Deploy
heroku create <app>

Deploy to Heroku

Cloud & Deploy
git push heroku main

Heroku logs

Cloud & Deploy
heroku logs --tail --app <app>

Set Heroku config var

Cloud & Deploy
heroku config:set <NAME>=<value> --app <app>

Run one-off Heroku command

Cloud & Deploy
heroku run bash --app <app>

Railway deploy

Cloud & Deploy
railway up

Render deploy hook

Cloud & Deploy
curl -X POST "<render-deploy-hook-url>"

Supabase local start

Cloud & Deploy
supabase start

Deploy Supabase edge function

Cloud & Deploy
supabase functions deploy <name>

Copy build to server over SSH

Cloud & Deploy
scp -r ./dist <user>@<host>:/var/www/app

Deploy with rsync over SSH

Cloud & Deploy
rsync -avz --delete ./dist/ <user>@<host>:/var/www/app/
Destructive

Run remote deploy script

Cloud & Deploy
ssh <user>@<host> 'cd /srv/app && ./deploy.sh'

Show kubectl contexts

Kubernetes
kubectl config get-contexts

Switch kubectl context

Kubernetes
kubectl config use-context <context>

Set default namespace

Kubernetes
kubectl config set-context --current --namespace=<ns>

List pods

Kubernetes
kubectl get pods

List pods in all namespaces

Kubernetes
kubectl get pods -A -o wide

Watch pods

Kubernetes
kubectl get pods -w

Describe a pod

Kubernetes
kubectl describe pod <pod>

Pod logs

Kubernetes
kubectl logs <pod>

Follow pod logs

Kubernetes
kubectl logs -f <pod> -c <container>

Previous container logs

Kubernetes

Read logs from the crashed instance of a restarting pod.

kubectl logs <pod> --previous

Shell into a pod

Kubernetes
kubectl exec -it <pod> -- /bin/sh

Port-forward a pod

Kubernetes
kubectl port-forward pod/<pod> 8080:80

Port-forward a service

Kubernetes
kubectl port-forward svc/<service> 8080:80

Apply a manifest

Kubernetes
kubectl apply -f <file>.yaml

Apply a directory of manifests

Kubernetes
kubectl apply -f ./k8s/

Delete resources from manifest

Kubernetes
kubectl delete -f <file>.yaml
Destructive

Restart a deployment

Kubernetes
kubectl rollout restart deployment/<name>

Rollout status

Kubernetes
kubectl rollout status deployment/<name>

Rollback a deployment

Kubernetes
kubectl rollout undo deployment/<name>

Rollout history

Kubernetes
kubectl rollout history deployment/<name>

Scale a deployment

Kubernetes
kubectl scale deployment/<name> --replicas=3

Autoscale a deployment

Kubernetes
kubectl autoscale deployment/<name> --min=2 --max=10 --cpu-percent=70

Set container image

Kubernetes
kubectl set image deployment/<name> <container>=<image>:<tag>

Edit a resource live

Kubernetes
kubectl edit deployment/<name>

Get resource YAML

Kubernetes
kubectl get deployment/<name> -o yaml

Cluster events by time

Kubernetes
kubectl get events --sort-by=.lastTimestamp

Top pods by resource use

Kubernetes
kubectl top pods

Top nodes by resource use

Kubernetes
kubectl top nodes

List nodes

Kubernetes
kubectl get nodes -o wide

Drain a node

Kubernetes
kubectl drain <node> --ignore-daemonsets --delete-emptydir-data
Destructive

Cordon a node

Kubernetes
kubectl cordon <node>

Uncordon a node

Kubernetes
kubectl uncordon <node>

Create secret from literals

Kubernetes
kubectl create secret generic <name> --from-literal=KEY=value

Decode a secret

Kubernetes
kubectl get secret <name> -o jsonpath="{.data.KEY}" | base64 -d

Create configmap from file

Kubernetes
kubectl create configmap <name> --from-file=./config.yaml

Copy file out of a pod

Kubernetes
kubectl cp <ns>/<pod>:/path/file ./file

Run a debug pod

Kubernetes
kubectl run tmp --rm -it --image=busybox -- sh

Debug a running pod

Kubernetes
kubectl debug -it <pod> --image=busybox --target=<container>

Explain a resource field

Kubernetes
kubectl explain deployment.spec.template

Dry-run a manifest

Kubernetes
kubectl apply -f <file>.yaml --dry-run=server

Install a Helm chart

Kubernetes
helm install <release> <chart>

Upgrade or install Helm release

Kubernetes
helm upgrade --install <release> <chart> -f values.yaml

List Helm releases

Kubernetes
helm list -A

Render Helm templates

Kubernetes
helm template <release> <chart> -f values.yaml

Rollback Helm release

Kubernetes
helm rollback <release> <revision>

Uninstall Helm release

Kubernetes
helm uninstall <release>
Destructive

Add Helm repo

Kubernetes
helm repo add <name> <url> && helm repo update

Build kustomize output

Kubernetes
kubectl kustomize ./overlays/prod

Apply kustomize overlay

Kubernetes
kubectl apply -k ./overlays/prod

Start minikube

Kubernetes
minikube start

Open minikube dashboard

Kubernetes
minikube dashboard

Load image into minikube

Kubernetes
minikube image load <image>:<tag>

Create kind cluster

Kubernetes
kind create cluster --name <name>

Open k9s dashboard

Kubernetes
k9s

Terraform init

DevOps
terraform init

Terraform format

DevOps
terraform fmt -recursive

Terraform validate

DevOps
terraform validate

Terraform plan to file

DevOps
terraform plan -out=tfplan

Terraform apply plan

DevOps
terraform apply tfplan

Terraform destroy

DevOps
terraform destroy
Destructive

Terraform show state

DevOps
terraform state list

Terraform import resource

DevOps
terraform import <address> <id>

Terraform target apply

DevOps
terraform apply -target=<address>

Terraform workspace switch

DevOps
terraform workspace select <name>

Terraform output value

DevOps
terraform output -raw <name>

Ansible ping hosts

DevOps
ansible all -m ping -i inventory.ini

Run Ansible playbook

DevOps
ansible-playbook -i inventory.ini site.yml

Ansible dry run

DevOps
ansible-playbook -i inventory.ini site.yml --check --diff

Install Ansible roles

DevOps
ansible-galaxy install -r requirements.yml

Encrypt Ansible vault file

DevOps
ansible-vault encrypt group_vars/prod/vault.yml

Packer build image

DevOps
packer build template.pkr.hcl

Pulumi deploy stack

DevOps
pulumi up

Connect to Postgres

Databases
psql "postgresql://<user>:<pass>@<host>:5432/<db>"

Run SQL file against Postgres

Databases
psql -d <db> -f ./schema.sql

Run one-off SQL query

Databases
psql -d <db> -c "SELECT count(*) FROM users;"

List Postgres tables

Databases
\dt

Describe Postgres table

Databases
\d+ <table>

List Postgres databases

Databases
\l

Toggle expanded output

Databases
\x

Dump a Postgres database

Databases
pg_dump -Fc <db> > backup.dump

Dump schema only

Databases
pg_dump --schema-only <db> > schema.sql

Restore a Postgres dump

Databases
pg_restore -d <db> --clean --if-exists backup.dump
Destructive

Create Postgres database

Databases
createdb <db>

Drop Postgres database

Databases
dropdb <db>
Destructive

Show running Postgres queries

Databases
SELECT pid, state, query FROM pg_stat_activity WHERE state <> 'idle';

Cancel a Postgres query

Databases
SELECT pg_cancel_backend(<pid>);

Table sizes in Postgres

Databases
SELECT relname, pg_size_pretty(pg_total_relation_size(relid)) FROM pg_catalog.pg_statio_user_tables ORDER BY pg_total_relation_size(relid) DESC;

Explain a slow query

Databases
EXPLAIN ANALYZE SELECT * FROM <table> WHERE <cond>;

Vacuum and analyze

Databases
VACUUM (ANALYZE, VERBOSE) <table>;

Connect to MySQL

Databases
mysql -h <host> -u <user> -p <db>

Dump a MySQL database

Databases
mysqldump -u <user> -p <db> > backup.sql

Restore a MySQL dump

Databases
mysql -u <user> -p <db> < backup.sql
Destructive

Show MySQL tables

Databases
SHOW TABLES;

Describe MySQL table

Databases
DESCRIBE <table>;

Show MySQL processlist

Databases
SHOW FULL PROCESSLIST;

Connect to MongoDB

Databases
mongosh "mongodb://<host>:27017/<db>"

List Mongo collections

Databases
show collections

Find Mongo documents

Databases
db.<collection>.find({ <field>: <value> }).limit(10)

Count Mongo documents

Databases
db.<collection>.countDocuments({})

Create Mongo index

Databases
db.<collection>.createIndex({ <field>: 1 })

Dump MongoDB

Databases
mongodump --uri="mongodb://<host>/<db>" --out=./dump

Restore MongoDB

Databases
mongorestore --uri="mongodb://<host>" ./dump
Destructive

Connect to Redis

Databases
redis-cli -h <host> -p 6379

Redis key count

Databases
redis-cli DBSIZE

Scan Redis keys by prefix

Databases
redis-cli --scan --pattern '<prefix>*'

Get Redis key TTL

Databases
redis-cli TTL <key>

Monitor Redis commands

Databases
redis-cli MONITOR

Flush a Redis database

Databases
redis-cli FLUSHDB
Destructive

Open SQLite database

Databases
sqlite3 <file>.db

List SQLite tables

Databases
.tables

Show SQLite schema

Databases
.schema <table>

Dump SQLite database

Databases
sqlite3 <file>.db .dump > dump.sql

Export SQLite query to CSV

Databases
sqlite3 -header -csv <file>.db "SELECT * FROM <table>;" > out.csv

Prisma generate client

Databases
npx prisma generate

Prisma create migration

Databases
npx prisma migrate dev --name <name>

Prisma deploy migrations

Databases
npx prisma migrate deploy

Prisma reset database

Databases
npx prisma migrate reset
Destructive

Prisma push schema

Databases
npx prisma db push

Open Prisma Studio

Databases
npx prisma studio

Drizzle generate migration

Databases
npx drizzle-kit generate

Drizzle push schema

Databases
npx drizzle-kit push

Open Drizzle Studio

Databases
npx drizzle-kit studio

Run Postgres in Docker

Databases
docker run --name pg -e POSTGRES_PASSWORD=<pass> -p 5432:5432 -d postgres:16

Run Redis in Docker

Databases
docker run --name redis -p 6379:6379 -d redis:7

Run MySQL in Docker

Databases
docker run --name mysql -e MYSQL_ROOT_PASSWORD=<pass> -p 3306:3306 -d mysql:8

Add a git worktree

Git

Check out another branch in a second folder without stashing.

git worktree add ../<dir> <branch>

List git worktrees

Git
git worktree list

Remove a git worktree

Git
git worktree remove ../<dir>

Start a bisect session

Git
git bisect start

Mark bisect good/bad

Git
git bisect good <sha> && git bisect bad <sha>

Automate bisect with a script

Git
git bisect run npm test

End a bisect session

Git
git bisect reset

Show reflog

Git

Find commits that seem lost after a reset or rebase.

git reflog

Recover a commit from reflog

Git
git reset --hard <reflog-sha>
Destructive

Clone with submodules

Git
git clone --recurse-submodules <repo-url>

Init and update submodules

Git
git submodule update --init --recursive

Update submodules to remote

Git
git submodule update --remote --merge

Sparse checkout a subfolder

Git
git sparse-checkout set <dir>

Enable sparse checkout (cone)

Git
git sparse-checkout init --cone

Search commit messages

Git
git log --grep="<text>"

Find when a line changed

Git
git log -S"<code snippet>" --oneline

Blame with line ranges

Git
git blame -L 10,40 <file>

Show a file at a revision

Git
git show <sha>:<path>

Restore a file from a commit

Git
git checkout <sha> -- <path>

Diff against a branch

Git
git diff <branch>...HEAD

Diff only file names

Git
git diff --name-only <branch>

Rebase interactively onto main

Git
git rebase -i origin/main

Continue an interrupted rebase

Git
git rebase --continue

Abort a rebase

Git
git rebase --abort

Force push safely

Git

Fails instead of overwriting someone else's new commits.

git push --force-with-lease
Destructive

Prune deleted remote branches

Git
git fetch --prune

Delete merged local branches

Git
git branch --merged main | grep -v main | xargs -r git branch -d
Destructive

Rename current branch

Git
git branch -m <new-name>

Create an annotated tag

Git
git tag -a v1.0.0 -m "release 1.0.0"

Push all tags

Git
git push --tags

Delete a remote tag

Git
git push origin :refs/tags/<tag>
Destructive

Cherry-pick a range

Git
git cherry-pick <start-sha>^..<end-sha>

Stash including untracked

Git
git stash push -u -m "<message>"

Apply a specific stash

Git
git stash apply stash@{1}

Show stash contents

Git
git stash show -p stash@{0}

Create a patch file

Git
git format-patch -1 <sha>

Apply a patch file

Git
git apply <file>.patch

Archive repo as zip

Git
git archive --format=zip HEAD -o source.zip

Repo size and object count

Git
git count-objects -vH

Garbage collect aggressively

Git
git gc --aggressive --prune=now

Set commit signing key

Git
git config --global user.signingkey <key-id>

Sign commits by default

Git
git config --global commit.gpgsign true

Ignore file mode changes

Git
git config core.fileMode false

Show config origin

Git
git config --list --show-origin

Alias a git command

Git
git config --global alias.lg "log --oneline --graph --decorate"

Sum a column with awk

Terminal
awk '{ sum += $2 } END { print sum }' <file>

Print selected columns

Terminal
awk '{ print $1, $3 }' <file>

Filter rows with awk

Terminal
awk '$3 > 100' <file>

Replace text in place

Terminal
sed -i 's/old/new/g' <file>
DestructiveLinux

Replace text in place (macOS)

Terminal
sed -i '' 's/old/new/g' <file>
DestructivemacOS

Print a line range

Terminal
sed -n '10,20p' <file>

Delete matching lines

Terminal
sed '/<pattern>/d' <file>

Bulk rename with xargs

Terminal
ls *.txt | xargs -I{} mv {} {}.bak

Parallel jobs with xargs

Terminal
cat urls.txt | xargs -P 8 -n 1 curl -sO

Find and delete safely

Terminal
find . -name "*.log" -mtime +7 -print -delete
Destructive

Find large files

Terminal
find . -type f -size +100M -exec ls -lh {} \;

Find and replace across repo

Terminal
rg -l "<old>" | xargs sed -i 's/<old>/<new>/g'
Destructive

Search with ripgrep

Terminal
rg -n "<pattern>" src/

Ripgrep only file names

Terminal
rg -l "<pattern>"

Count matches

Terminal
rg -c "<pattern>"

Who is using a port

Terminal
lsof -i :3000
macOSLinux

Kill process on a port

Terminal
kill -9 $(lsof -t -i:3000)
Destructive

List listening sockets

Terminal
ss -tulpn
Linux

DNS lookup

Terminal
dig +short <domain>

Trace DNS resolution

Terminal
dig <domain> +trace

Check certificate expiry

Terminal
echo | openssl s_client -connect <host>:443 2>/dev/null | openssl x509 -noout -dates

Generate a random secret

Terminal
openssl rand -base64 32

Hash a file

Terminal
shasum -a 256 <file>

Generate an SSH key

Terminal
ssh-keygen -t ed25519 -C "<email>"

Copy SSH key to server

Terminal
ssh-copy-id <user>@<host>

SSH tunnel a remote port

Terminal
ssh -L 5432:localhost:5432 <user>@<host>

Time a command

Terminal
time <command>

Run command every 2 seconds

Terminal
watch -n 2 '<command>'
Linux

Follow a log file

Terminal
tail -f -n 100 <file>

Follow and filter a log

Terminal
tail -f <file> | grep --line-buffered "ERROR"

Disk usage by folder

Terminal
du -sh * | sort -h

Free disk space

Terminal
df -h

Top processes by memory

Terminal
ps aux --sort=-%mem | head -n 15
Linux

Run in background with nohup

Terminal
nohup <command> > out.log 2>&1 &

List background jobs

Terminal
jobs -l

Bring job to foreground

Terminal
fg %1

New tmux session

Terminal
tmux new -s <name>

Attach tmux session

Terminal
tmux attach -t <name>

List tmux sessions

Terminal
tmux ls

Pretty-print JSON

Terminal
cat <file>.json | jq .

Extract JSON field

Terminal
jq -r '.items[].name' <file>.json

Filter JSON array

Terminal
jq '.[] | select(.status == "active")' <file>.json

Convert JSON to CSV

Terminal
jq -r '.[] | [.id, .name] | @csv' <file>.json

Parse YAML with yq

Terminal
yq '.services.web.image' docker-compose.yml

Compress a folder

Terminal
tar -czf archive.tar.gz <dir>

Extract an archive

Terminal
tar -xzf archive.tar.gz

List archive contents

Terminal
tar -tzf archive.tar.gz

Download with resume

Terminal
curl -C - -O <url>

POST JSON with curl

Terminal
curl -X POST <url> -H "Content-Type: application/json" -d '{"key":"value"}'

Show only HTTP status

Terminal
curl -s -o /dev/null -w "%{http_code}\n" <url>

Measure request timing

Terminal
curl -s -o /dev/null -w "dns:%{time_namelookup} connect:%{time_connect} total:%{time_total}\n" <url>

Mirror a site section

Terminal
wget -r -np -k <url>

Edit crontab

Terminal
crontab -e

List cron jobs

Terminal
crontab -l

Restart a systemd service

Terminal
sudo systemctl restart <service>
Linux

Service status

Terminal
systemctl status <service>
Linux

Follow service logs

Terminal
journalctl -u <service> -f
Linux

Enable service on boot

Terminal
sudo systemctl enable --now <service>
Linux

Change file owner

Terminal
sudo chown -R <user>:<group> <path>

Make a script executable

Terminal
chmod +x <script>.sh

Create a symlink

Terminal
ln -s <target> <linkname>

Show environment variable

Terminal
printenv <NAME>

Load .env into shell

Terminal
set -a && source .env && set +a

Diff two directories

Terminal
diff -rq <dir-a> <dir-b>

Sort and dedupe a file

Terminal
sort <file> | uniq -c | sort -rn

Split a large file

Terminal
split -l 100000 <file> chunk_

Copy output to clipboard (macOS)

Terminal
<command> | pbcopy
macOS

Copy output to clipboard (Linux)

Terminal
<command> | xclip -selection clipboard
Linux

Enable corepack

npm/yarn

Use the package manager version pinned in package.json.

corepack enable

Pin package manager

npm/yarn
corepack use pnpm@latest

Clean install from lockfile

npm/yarn
npm ci

Audit and fix vulnerabilities

npm/yarn
npm audit fix

Audit production only

npm/yarn
npm audit --omit=dev

List outdated packages

npm/yarn
npm outdated

Update to latest majors

npm/yarn
npx npm-check-updates -u && npm install

Why is a package installed

npm/yarn
npm explain <package>

Dependency tree depth 0

npm/yarn
npm ls --depth=0

Run script in all workspaces

npm/yarn
npm run <script> --workspaces --if-present

Install into one workspace

npm/yarn
npm install <package> -w <workspace>

pnpm install frozen lockfile

npm/yarn
pnpm install --frozen-lockfile

pnpm run in all packages

npm/yarn
pnpm -r run build

pnpm filter a package

npm/yarn
pnpm --filter <package> dev

pnpm add to workspace root

npm/yarn
pnpm add -w -D <package>

pnpm dedupe

npm/yarn
pnpm dedupe

pnpm prune store

npm/yarn
pnpm store prune

bun install

npm/yarn
bun install

bun add dev dependency

npm/yarn
bun add -d <package>

bun run a script

npm/yarn
bun run <script>

bun run a file

npm/yarn
bun <file>.ts

bunx a package

npm/yarn
bunx <package>

bun test

npm/yarn
bun test

yarn install immutable

npm/yarn
yarn install --immutable

yarn workspace command

npm/yarn
yarn workspace <name> <script>

yarn upgrade interactive

npm/yarn
yarn upgrade-interactive

Publish a package

npm/yarn
npm publish --access public

Publish a prerelease tag

npm/yarn
npm publish --tag next

Bump version and tag

npm/yarn
npm version minor -m "release %s"

Dry-run a publish

npm/yarn
npm publish --dry-run

Pack a tarball

npm/yarn
npm pack

Link a local package

npm/yarn
npm link <package>

Deprecate a version

npm/yarn
npm deprecate <package>@<version> "<message>"

Set npm registry

npm/yarn
npm config set registry <url>

Login to npm registry

npm/yarn
npm login

Clear npm cache

npm/yarn
npm cache clean --force
Destructive

Install exact version

npm/yarn
npm install <package>@<version> --save-exact

Reinstall node_modules

npm/yarn
rm -rf node_modules package-lock.json && npm install
Destructive

Install and use Node LTS

Node.js
nvm install --lts && nvm use --lts

Use project Node version

Node.js
nvm use

Set default Node version

Node.js
nvm alias default 20

Run a TS file directly

Node.js
npx tsx <file>.ts

Typecheck without emitting

Node.js
npx tsc --noEmit

Lint and autofix

Node.js
npx eslint . --fix

Format with Prettier

Node.js
npx prettier --write .

Debug Node with inspector

Node.js
node --inspect-brk <file>.js

Heap snapshot on OOM

Node.js
node --heap-prof <file>.js

Raise Node memory limit

Node.js
NODE_OPTIONS=--max-old-space-size=4096 npm run build

Analyze Vite bundle

Frontend
npx vite-bundle-visualizer

Preview a production build

Frontend
npm run build && npm run preview

Run Playwright tests

Frontend
npx playwright test

Playwright UI mode

Frontend
npx playwright test --ui

Run Vitest once

Frontend
npx vitest run

Vitest coverage

Frontend
npx vitest run --coverage

Lighthouse audit

Performance
npx lighthouse <url> --view

Check bundle size limits

Performance
npx size-limit

Build with buildx

Docker
docker buildx build -t <image>:<tag> .

Multi-platform build and push

Docker
docker buildx build --platform linux/amd64,linux/arm64 -t <image>:<tag> --push .

Create a buildx builder

Docker
docker buildx create --use --name builder

Build with no cache

Docker
docker build --no-cache -t <image>:<tag> .

Build a specific stage

Docker
docker build --target builder -t <image>:dev .

Pass build args

Docker
docker build --build-arg NODE_ENV=production -t <image>:<tag> .

Tag an image

Docker
docker tag <image>:<tag> <registry>/<image>:<tag>

Push an image

Docker
docker push <registry>/<image>:<tag>

Login to a registry

Docker
docker login <registry>

Inspect image layers

Docker
docker history <image>:<tag>

Inspect image config

Docker
docker inspect <image>:<tag>

Check container health

Docker
docker inspect --format='{{.State.Health.Status}}' <container>

Container resource usage

Docker
docker stats --no-stream

Follow container logs

Docker
docker logs -f --tail 100 <container>

Shell into a container

Docker
docker exec -it <container> sh

Run a throwaway container

Docker
docker run --rm -it <image> sh

Mount current dir into container

Docker
docker run --rm -v "$PWD":/app -w /app <image> <command>

Publish a port

Docker
docker run -p 8080:80 -d <image>

Pass env file to container

Docker
docker run --env-file .env -d <image>

Copy file out of a container

Docker
docker cp <container>:/path/file ./file

Commit a container to an image

Docker
docker commit <container> <image>:<tag>

Save an image to a tar

Docker
docker save -o image.tar <image>:<tag>

Load an image from tar

Docker
docker load -i image.tar

Prune dangling images

Docker
docker image prune
Destructive

Prune everything unused

Docker

Removes stopped containers, unused images and volumes.

docker system prune -a --volumes
Destructive

Show docker disk usage

Docker
docker system df

List volumes

Docker
docker volume ls

Inspect a volume

Docker
docker volume inspect <volume>

Backup a volume

Docker
docker run --rm -v <volume>:/data -v "$PWD":/backup alpine tar czf /backup/volume.tar.gz /data

List networks

Docker
docker network ls

Connect container to network

Docker
docker network connect <network> <container>

Compose up detached

Docker
docker compose up -d

Compose up and rebuild

Docker
docker compose up -d --build

Compose down with volumes

Docker
docker compose down -v
Destructive

Compose logs for a service

Docker
docker compose logs -f <service>

Compose exec into a service

Docker
docker compose exec <service> sh

Compose run one-off command

Docker
docker compose run --rm <service> <command>

Compose restart a service

Docker
docker compose restart <service>

Compose scale a service

Docker
docker compose up -d --scale <service>=3

Validate compose config

Docker
docker compose config

Compose with override file

Docker
docker compose -f docker-compose.yml -f docker-compose.prod.yml up -d

Scan an image for CVEs

Security
docker scout cves <image>:<tag>

Trivy image scan

Security
trivy image <image>:<tag>

Scan dependencies for CVEs

Security
npx audit-ci --moderate

Scan repo for secrets

Security
npx secretlint "**/*"

gitleaks secret scan

Security
gitleaks detect --source . --verbose

Run a model with Ollama

AI
ollama run <model>

Pull an Ollama model

AI
ollama pull <model>

List local Ollama models

AI
ollama list

Remove an Ollama model

AI
ollama rm <model>
Destructive

Serve Ollama API

AI
ollama serve

Call Ollama chat API

AI
curl http://localhost:11434/api/chat -d '{"model":"<model>","messages":[{"role":"user","content":"hi"}]}'

Create model from Modelfile

AI
ollama create <name> -f Modelfile

Show Ollama model details

AI
ollama show <model> --modelfile

Download a Hugging Face model

AI
huggingface-cli download <repo-id> --local-dir ./models/<name>

Login to Hugging Face

AI
huggingface-cli login

Upload to Hugging Face

AI
huggingface-cli upload <repo-id> ./local-dir

Serve a model with vLLM

AI
python -m vllm.entrypoints.openai.api_server --model <model>

Quantize with llama.cpp

AI
./llama-quantize model-f16.gguf model-q4_k_m.gguf q4_k_m

Run llama.cpp server

AI
./llama-server -m ./models/<model>.gguf -c 8192

Check GPU utilization

AI
nvidia-smi

Watch GPU utilization

AI
watch -n 1 nvidia-smi

Verify CUDA in PyTorch

AI
python -c "import torch; print(torch.cuda.is_available(), torch.cuda.device_count())"

Pick a GPU device

AI
CUDA_VISIBLE_DEVICES=0 python train.py

Create a Python venv

Python
python -m venv .venv && source .venv/bin/activate

Freeze Python requirements

Python
pip freeze > requirements.txt

Install from requirements

Python
pip install -r requirements.txt

Create uv project

Python
uv init && uv add <package>

Run with uv

Python
uv run python <file>.py

Create a conda env

Python
conda create -n <name> python=3.11 -y

Activate a conda env

Python
conda activate <name>

Export conda env

Python
conda env export > environment.yml

Format Python with ruff

Python
ruff format .

Lint Python with ruff

Python
ruff check . --fix

Run pytest verbosely

Python
pytest -v -x