Skip to content

free_tool

Terminal, Git & AWS Command Cheat Sheet

The commands I actually reach for, grouped by the job you're doing: moving around the shell, undoing a Git mistake, syncing to S3, querying a CSV with DuckDB, following a pod's logs. Search with /, copy with one click. Anything that deletes data is marked.

Terminal

Everyday shell work: moving around, reading files, finding things, managing processes.

Navigate

  • pwd

    Print the folder you're in.

  • ls -la

    List all files, including hidden ones, with permissions, size and date.

  • ls -lhS

    List files by size, largest first, in human units (K, M, G).

  • cd <dir> · cd .. · cd - · cd ~

    Go into a folder · up one level · back to the previous folder · home.

  • tree -L 2

    Show the folder structure two levels deep (brew install tree).

  • open .

    macOS: open the current folder in Finder. On Linux use xdg-open.

  • code .

    Open the current folder in VS Code.

Files and folders

  • mkdir -p a/b/c

    Create nested folders in one go; no error if they already exist.

  • touch file.txt

    Create an empty file, or update the timestamp of an existing one.

  • cp -r src/ dest/

    Copy a folder and everything in it.

  • mv old.txt new.txt

    Rename or move a file.

  • rm -rf <dir>

    Destructive ·Delete a folder and everything in it, with no undo. Check the path first.

  • ln -s <target> <link>

    Create a symbolic link (shortcut).

  • chmod +x script.sh

    Make a script executable.

  • chmod 600 key.pem

    Owner-only read/write access; required for SSH keys.

  • chown user:group file

    Change a file's owner (usually needs sudo).

Read files

  • cat file

    Print the whole file.

  • less file

    Scroll through a large file. Keys: / search, n next match, G end, q quit.

  • head -n 20 file · tail -n 20 file

    Show the first or last 20 lines.

  • tail -f app.log

    Follow a log live as new lines are written.

  • wc -l file

    Count lines. A quick row count for a CSV.

  • diff -u a.txt b.txt

    Show line-by-line differences between two files.

Search

  • grep -rn "text" .

    Search every file under this folder; show file and line number.

  • grep -i -v "debug" app.log

    -i ignores case, -v keeps only the lines that DON'T match.

  • rg "pattern"

    ripgrep: much faster grep that skips .gitignore'd files (brew install ripgrep).

  • find . -name "*.csv" -mtime -1

    Find CSV files changed in the last day.

  • find . -type f -size +100M

    Find files larger than 100 MB.

  • fd pattern

    A simpler, faster find (brew install fd).

Text processing (pipes)

  • cmd1 | cmd2

    Pipe: send the output of cmd1 into cmd2.

  • cmd > out.txt · cmd >> out.txt

    Write output to a file (overwrite) · append to it.

  • cmd 2>&1 | tee run.log

    Merge errors into output, show it on screen, and save it to a file.

  • sort | uniq -c | sort -rn

    Count how often each line appears, most frequent first.

  • cut -d, -f1,3 data.csv

    Take columns 1 and 3 from a comma-separated file.

  • awk -F, '{s+=$3} END{print s}' data.csv

    Sum column 3 of a CSV.

  • sed -i '' 's/old/new/g' file

    Replace text in place (macOS form; on Linux drop the '').

  • xargs -n1 -P4 <cmd>

    Run a command on each input line, 4 at a time in parallel.

Processes and system

  • ps aux | grep <name>

    Find a running process and its PID.

  • top · htop

    Live CPU and memory by process (htop: brew install htop).

  • kill <pid> · kill -9 <pid>

    Ask a process to stop · force-kill it.

  • lsof -i :3000

    Show which process is using port 3000.

  • kill $(lsof -t -i :3000)

    Destructive ·Free a stuck port by killing whatever is on it.

  • cmd & · jobs · fg

    Run in the background · list background jobs · bring one back.

  • nohup cmd > out.log 2>&1 &

    Keep a command running after you close the terminal.

  • df -h · du -sh *

    Free disk space · size of each item in this folder.

  • history | grep <word>

    Find a command you ran earlier. Ctrl+R searches interactively.

Environment

  • echo $PATH | tr ':' '\n'

    Show each folder the shell searches for commands, one per line.

  • which <cmd> · type <cmd>

    Show where a command lives, or whether it's an alias or function.

  • export KEY=value

    Set an environment variable for this session.

  • env | grep AWS

    Show environment variables matching a word.

  • source ~/.zshrc

    Reload your shell config without opening a new terminal.

  • alias gs='git status'

    Create a shortcut. Put it in ~/.zshrc to keep it.

Network and remote

  • curl -sS https://api.example.com | jq

    Call an API and pretty-print the JSON.

  • curl -X POST -H 'Content-Type: application/json' -d '{"a":1}' <url>

    Send a JSON POST request.

  • curl -I <url>

    Show only the response headers.

  • ping host · nc -zv host 5432

    Check a host is reachable · check a port is open.

  • dig example.com +short

    Look up a domain's DNS records.

  • ssh -i key.pem user@host

    Log in to a remote server with a key.

  • scp file user@host:/path

    Copy a file to a server.

  • rsync -avz --progress src/ user@host:/dest/

    Sync a folder, copying only what changed. Add --delete to mirror exactly.

  • ssh -L 5433:db-host:5432 user@bastion

    Tunnel: reach a private database at localhost:5433 through a jump host.

Archives

  • tar -czf out.tar.gz folder/

    Compress a folder.

  • tar -xzf file.tar.gz

    Extract a .tar.gz file.

  • zip -r out.zip folder/ · unzip file.zip

    Create or extract a zip file.

  • gzip -k big.csv · gunzip big.csv.gz

    Compress a file (keeping the original) · decompress.

Sessions and scheduling

  • tmux new -s work

    Start a named session that survives disconnects.

  • tmux attach -t work

    Reattach to it. Ctrl+B then D detaches.

  • crontab -e · crontab -l

    Edit or list scheduled jobs.

  • 0 2 * * * /path/job.sh >> /tmp/job.log 2>&1

    Cron line: run a job every day at 02:00 and log its output.

Git

Version control: branching, committing, syncing, and undoing mistakes safely.

Setup

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

    Set the author name on your commits (and user.email the same way).

  • git config --global init.defaultBranch main

    Make new repos start on a branch called main.

  • git clone <url>

    Download a repository.

  • git init

    Turn the current folder into a new repository.

Daily loop

  • git status -sb

    Short status: what changed and whether you're ahead or behind.

  • git diff · git diff --staged

    Changes not yet staged · changes staged for the next commit.

  • git add <file> · git add -p

    Stage a file · stage chosen chunks interactively.

  • git commit -m "message"

    Commit what's staged.

  • git commit --amend

    Fix the last commit's message or add forgotten files. Only before you push.

  • git pull --rebase

    Get remote changes and replay your commits on top, keeping history straight.

  • git push -u origin <branch>

    Push a new branch and set it to track the remote.

Branches

  • git switch -c <branch>

    Create a branch and switch to it.

  • git switch <branch>

    Switch to an existing branch.

  • git branch -a

    List local and remote branches.

  • git branch -d <branch>

    Destructive ·Delete a merged local branch. -D forces it.

  • git fetch --prune

    Update remote branches and drop ones deleted on the server.

  • git merge <branch>

    Merge a branch into the current one.

  • git rebase origin/main

    Replay your branch on top of the latest main.

  • git worktree add ../feat <branch>

    Check out a second branch in another folder at the same time.

History

  • git log --oneline --graph --all -20

    A compact picture of recent history across branches.

  • git log -p <file>

    Every change ever made to one file.

  • git log -S "text"

    Find the commit that added or removed some text.

  • git blame <file>

    Who last changed each line, and in which commit.

  • git show <sha>

    Show one commit's changes.

  • git reflog

    Everything HEAD pointed to recently. Use it to recover 'lost' commits.

Undo

  • git restore <file>

    Destructive ·Discard unstaged changes to a file.

  • git restore --staged <file>

    Unstage a file but keep the changes.

  • git reset --soft HEAD~1

    Undo the last commit and keep its changes staged.

  • git reset --hard HEAD~1

    Destructive ·Throw away the last commit AND its changes.

  • git revert <sha>

    Add a new commit that undoes an old one. Safe on shared branches.

  • git clean -fd

    Destructive ·Delete untracked files and folders. Preview first with -n.

  • git stash · git stash pop

    Shelve uncommitted work · bring it back.

  • git cherry-pick <sha>

    Copy one commit onto the current branch.

Remotes and releases

  • git remote -v

    Show where this repo pushes and pulls.

  • git tag v1.2.0 && git push --tags

    Tag a release and push the tag.

  • git push --force-with-lease

    Destructive ·Force-push only if nobody else has pushed since. Never on main.

  • gh pr create --fill

    GitHub CLI: open a pull request from this branch.

  • gh pr checkout <number>

    Check out someone's pull request locally.

  • gh run watch

    Watch the current CI run live.

AWS CLI

Add --profile <name> to target an account and --region <region> to target a region. Add --output table or a --query filter to make output readable.

Sign-in and identity

  • aws configure

    Set up an access-key profile interactively.

  • aws configure sso

    Set up an SSO profile.

  • aws sso login --profile <name>

    Refresh an expired SSO login.

  • aws sts get-caller-identity

    Check which account and user or role you're using. Always run this first.

  • aws configure list-profiles

    List your profiles.

  • export AWS_PROFILE=<name>

    Use one profile for the rest of this terminal session.

S3

  • aws s3 ls · aws s3 ls s3://bucket/prefix/ --recursive --human-readable --summarize

    List buckets · list objects with sizes and a total.

  • aws s3 cp file.csv s3://bucket/path/

    Upload a file. Swap the two arguments to download.

  • aws s3 sync ./data s3://bucket/data/

    Destructive ·Upload only new or changed files. --delete removes extra files at the destination.

  • aws s3 rm s3://bucket/path/ --recursive

    Destructive ·Delete everything under a prefix. Preview with --dryrun.

  • aws s3 presign s3://bucket/file --expires-in 3600

    Make a download link that works for one hour.

  • aws s3api head-object --bucket b --key k

    Show an object's size, type and metadata.

EC2 and servers

  • aws ec2 describe-instances --query 'Reservations[].Instances[].[InstanceId,State.Name,Tags[?Key==`Name`].Value|[0]]' --output table

    List instances with their state and name.

  • aws ec2 start-instances --instance-ids i-123

    Start an instance (stop-instances to stop it).

  • aws ssm start-session --target i-123

    Open a shell on an instance with no SSH key or open port.

  • aws ssm send-command --document-name AWS-RunShellScript --targets Key=instanceids,Values=i-123 --parameters commands='df -h'

    Run a command on an instance remotely.

Logs and monitoring

  • aws logs tail /aws/lambda/<fn> --follow --since 10m

    Follow a log group live.

  • aws logs filter-log-events --log-group-name <g> --filter-pattern ERROR

    Search a log group for a word.

  • aws cloudwatch get-metric-statistics …

    Pull metric data points, such as CPU, for a time range.

IAM and secrets

  • aws iam list-users · list-roles

    List users or roles.

  • aws iam list-attached-role-policies --role-name <r>

    See which policies a role has.

  • aws secretsmanager get-secret-value --secret-id <id> --query SecretString --output text

    Read a secret.

  • aws ssm get-parameter --name /app/db_url --with-decryption

    Read a Parameter Store value.

Data services

  • aws athena start-query-execution --query-string "SELECT …" --result-configuration OutputLocation=s3://bucket/athena/

    Run an Athena SQL query over S3 data.

  • aws athena get-query-results --query-execution-id <id>

    Fetch that query's results.

  • aws glue start-job-run --job-name <job>

    Start a Glue ETL job.

  • aws glue get-job-runs --job-name <job> --max-items 5

    Check a Glue job's recent runs.

  • aws glue get-tables --database-name <db>

    List tables in the Glue Data Catalog.

  • aws redshift-data execute-statement --workgroup-name <wg> --database dev --sql "SELECT 1"

    Run SQL on Redshift Serverless with no database driver.

  • aws emr list-clusters --active

    List running EMR (Spark) clusters.

  • aws kinesis list-streams

    List Kinesis data streams.

  • aws rds describe-db-instances --query 'DBInstances[].[DBInstanceIdentifier,DBInstanceStatus,Endpoint.Address]' --output table

    List databases with their status and endpoint.

Lambda and Bedrock

  • aws lambda list-functions --query 'Functions[].FunctionName'

    List Lambda functions.

  • aws lambda invoke --function-name <fn> --payload '{}' --cli-binary-format raw-in-base64-out out.json

    Run a function and save its response.

  • aws bedrock list-foundation-models --region us-east-1 --query 'modelSummaries[].modelId'

    List the models Bedrock offers in a region.

  • aws bedrock-runtime converse --model-id <id> --messages '[{"role":"user","content":[{"text":"hi"}]}]'

    Send one test prompt to a model (billed).

Cost and housekeeping

  • aws ce get-cost-and-usage --time-period Start=<yyyy-mm-01>,End=<yyyy-mm-dd> --granularity MONTHLY --metrics UnblendedCost

    Spend for a date range, e.g. this month so far.

  • aws cloudformation describe-stacks --query 'Stacks[].[StackName,StackStatus]' --output table

    List CloudFormation stacks and their status.

Data engineering

Databases, file formats, Python environments, containers, orchestration and big-data jobs.

PostgreSQL (psql)

  • psql "postgresql://user:pass@host:5432/db"

    Connect to a database.

  • \l · \dt · \d table · \dn

    Inside psql: list databases · tables · a table's columns · schemas.

  • \x auto · \timing on

    Readable output for wide rows · show how long each query takes.

  • \copy t TO 'out.csv' CSV HEADER

    Export a table (or a query in parentheses) to a local CSV.

  • \copy t FROM 'in.csv' CSV HEADER

    Load a local CSV into a table.

  • EXPLAIN (ANALYZE, BUFFERS) SELECT …;

    Show the query plan and real timings. The first tool for a slow query.

  • pg_dump -Fc db > db.dump · pg_restore -d db db.dump

    Back up · restore a database.

DuckDB (fast local SQL on files)

  • duckdb

    Open an in-memory analytics shell (brew install duckdb).

  • SELECT * FROM 'data/*.parquet' LIMIT 10;

    Query Parquet or CSV files directly; no loading step.

  • COPY (SELECT …) TO 'out.parquet' (FORMAT parquet);

    Convert or export to Parquet.

  • DESCRIBE SELECT * FROM 'file.csv';

    See the column types DuckDB infers from a file.

JSON and CSV

  • jq '.items[] | {id, name}' data.json

    Pick fields out of JSON.

  • jq -r '.[] | [.id,.name] | @csv' data.json

    Turn a JSON array into CSV.

  • csvlook data.csv | less -S

    View a CSV as an aligned table (pip install csvkit).

  • csvstat data.csv

    Per-column stats: types, nulls, min and max.

  • column -s, -t < data.csv | less -S

    Quick table view with no install.

Python environments

  • python3 -m venv .venv && source .venv/bin/activate

    Create and turn on a project virtual environment.

  • pip install -r requirements.txt

    Install a project's dependencies.

  • pip freeze > requirements.txt

    Save exact installed versions.

  • uv venv · uv pip install pandas

    uv: a much faster venv and pip replacement.

  • python -m http.server 8000

    Serve the current folder over HTTP.

  • jupyter lab

    Start notebooks in the browser.

Docker

  • docker ps -a

    List containers, including stopped ones.

  • docker compose up -d · docker compose down

    Start a stack in the background · stop and remove it.

  • docker logs -f <container>

    Follow a container's logs.

  • docker exec -it <container> bash

    Open a shell inside a running container.

  • docker run --rm -p 5432:5432 -e POSTGRES_PASSWORD=pw postgres:16

    Throwaway local Postgres.

  • docker build -t app:dev .

    Build an image from the Dockerfile here.

  • docker system prune -a

    Destructive ·Free disk space: removes unused images, containers and cache.

Kubernetes

  • kubectl get pods -n <ns>

    List pods in a namespace.

  • kubectl logs -f <pod>

    Follow a pod's logs.

  • kubectl describe pod <pod>

    See why a pod is failing: events and restarts.

  • kubectl exec -it <pod> -- sh

    Shell into a pod.

  • kubectl port-forward svc/<svc> 8080:80

    Reach a cluster service on localhost:8080.

Spark, Airflow and dbt

  • spark-submit --master yarn --deploy-mode cluster job.py

    Submit a PySpark job to a cluster.

  • pyspark

    Interactive Spark shell in Python.

  • airflow dags list · airflow dags trigger <dag_id>

    List DAGs · start a run.

  • airflow tasks test <dag> <task> <yyyy-mm-dd>

    Run one task locally without the scheduler.

  • dbt debug

    Check dbt's connection and project setup.

  • dbt run --select model_name+

    Build a model and everything downstream of it.

  • dbt test · dbt build

    Run data tests · run models and tests together.

  • dbt docs generate && dbt docs serve

    Browse lineage and docs in the browser.

Moving and checking data

  • rsync -avz --partial src/ dest/

    Resumable folder copy.

  • split -l 1000000 big.csv part_

    Split a huge CSV into 1M-line pieces.

  • shasum -a 256 file

    Checksum a file to confirm a transfer arrived intact.

  • iconv -f latin1 -t utf-8 in.csv > out.csv

    Fix text-encoding problems.

  • file data.csv

    Detect a file's type and encoding.

macOS / zsh defaults; Linux-only differences are noted. <angle brackets> mark values to replace. AWS commands take --profile and --region like any other.

read_before_you_run

Check where you are before you change anything

Most terminal accidents aren't typos in the command; they're the command running in the wrong place. pwd before a recursive delete, git status before a reset, and aws sts get-caller-identity before touching a bucket each take a second and answer the question that matters: which folder, branch or account am I about to change?

Prefer the reversible form when there is one. git revert over git reset --hard on a shared branch, --force-with-lease over --force, and --dryrun on an S3 delete before the real one.

faq

Questions & answers

What's in the command cheat sheet?
Over 190 commands in four sections: everyday terminal work, Git, the AWS CLI, and data engineering (psql, DuckDB, jq, Python environments, Docker, kubectl, Spark, Airflow and dbt). Each has a plain-English explanation, and commands that delete or overwrite data are marked.
How do I find a command quickly?
Press / to jump to the search box and type any word from the command or what you want to do, such as "undo commit", "s3 sync" or "port". Every word must match, so adding a second word narrows the list. Escape clears the search.
Do the commands work on Linux and Windows?
They are written for macOS with zsh, and nearly all work unchanged on Linux; where a flag differs, such as sed -i, the description says so. On Windows, use them inside WSL or Git Bash.
What do the angle brackets mean?
Anything in <angle brackets> is a placeholder, such as <branch> or <instance-id>. Replace it, brackets included, with your own value before running the command.