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
pwdPrint the folder you're in.
ls -laList all files, including hidden ones, with permissions, size and date.
ls -lhSList 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 2Show 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/cCreate nested folders in one go; no error if they already exist.
touch file.txtCreate 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.txtRename 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.shMake a script executable.
chmod 600 key.pemOwner-only read/write access; required for SSH keys.
chown user:group fileChange a file's owner (usually needs sudo).
Read files
cat filePrint the whole file.
less fileScroll through a large file. Keys: / search, n next match, G end, q quit.
head -n 20 file · tail -n 20 fileShow the first or last 20 lines.
tail -f app.logFollow a log live as new lines are written.
wc -l fileCount lines. A quick row count for a CSV.
diff -u a.txt b.txtShow 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 -1Find CSV files changed in the last day.
find . -type f -size +100MFind files larger than 100 MB.
fd patternA simpler, faster find (brew install fd).
Text processing (pipes)
cmd1 | cmd2Pipe: send the output of cmd1 into cmd2.
cmd > out.txt · cmd >> out.txtWrite output to a file (overwrite) · append to it.
cmd 2>&1 | tee run.logMerge errors into output, show it on screen, and save it to a file.
sort | uniq -c | sort -rnCount how often each line appears, most frequent first.
cut -d, -f1,3 data.csvTake columns 1 and 3 from a comma-separated file.
awk -F, '{s+=$3} END{print s}' data.csvSum column 3 of a CSV.
sed -i '' 's/old/new/g' fileReplace 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 · htopLive CPU and memory by process (htop: brew install htop).
kill <pid> · kill -9 <pid>Ask a process to stop · force-kill it.
lsof -i :3000Show which process is using port 3000.
kill $(lsof -t -i :3000)Destructive ·Free a stuck port by killing whatever is on it.
cmd & · jobs · fgRun 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=valueSet an environment variable for this session.
env | grep AWSShow environment variables matching a word.
source ~/.zshrcReload 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 | jqCall 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 5432Check a host is reachable · check a port is open.
dig example.com +shortLook up a domain's DNS records.
ssh -i key.pem user@hostLog in to a remote server with a key.
scp file user@host:/pathCopy 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@bastionTunnel: 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.gzExtract a .tar.gz file.
zip -r out.zip folder/ · unzip file.zipCreate or extract a zip file.
gzip -k big.csv · gunzip big.csv.gzCompress a file (keeping the original) · decompress.
Sessions and scheduling
tmux new -s workStart a named session that survives disconnects.
tmux attach -t workReattach to it. Ctrl+B then D detaches.
crontab -e · crontab -lEdit or list scheduled jobs.
0 2 * * * /path/job.sh >> /tmp/job.log 2>&1Cron 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 mainMake new repos start on a branch called main.
git clone <url>Download a repository.
git initTurn the current folder into a new repository.
Daily loop
git status -sbShort status: what changed and whether you're ahead or behind.
git diff · git diff --stagedChanges not yet staged · changes staged for the next commit.
git add <file> · git add -pStage a file · stage chosen chunks interactively.
git commit -m "message"Commit what's staged.
git commit --amendFix the last commit's message or add forgotten files. Only before you push.
git pull --rebaseGet 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 -aList local and remote branches.
git branch -d <branch>Destructive ·Delete a merged local branch. -D forces it.
git fetch --pruneUpdate remote branches and drop ones deleted on the server.
git merge <branch>Merge a branch into the current one.
git rebase origin/mainReplay 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 -20A 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 reflogEverything 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~1Undo the last commit and keep its changes staged.
git reset --hard HEAD~1Destructive ·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 -fdDestructive ·Delete untracked files and folders. Preview first with -n.
git stash · git stash popShelve uncommitted work · bring it back.
git cherry-pick <sha>Copy one commit onto the current branch.
Remotes and releases
git remote -vShow where this repo pushes and pulls.
git tag v1.2.0 && git push --tagsTag a release and push the tag.
git push --force-with-leaseDestructive ·Force-push only if nobody else has pushed since. Never on main.
gh pr create --fillGitHub CLI: open a pull request from this branch.
gh pr checkout <number>Check out someone's pull request locally.
gh run watchWatch 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 configureSet up an access-key profile interactively.
aws configure ssoSet up an SSO profile.
aws sso login --profile <name>Refresh an expired SSO login.
aws sts get-caller-identityCheck which account and user or role you're using. Always run this first.
aws configure list-profilesList 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 --summarizeList 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/ --recursiveDestructive ·Delete everything under a prefix. Preview with --dryrun.
aws s3 presign s3://bucket/file --expires-in 3600Make a download link that works for one hour.
aws s3api head-object --bucket b --key kShow 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 tableList instances with their state and name.
aws ec2 start-instances --instance-ids i-123Start an instance (stop-instances to stop it).
aws ssm start-session --target i-123Open 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 10mFollow a log group live.
aws logs filter-log-events --log-group-name <g> --filter-pattern ERRORSearch 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-rolesList 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 textRead a secret.
aws ssm get-parameter --name /app/db_url --with-decryptionRead 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 5Check 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 --activeList running EMR (Spark) clusters.
aws kinesis list-streamsList Kinesis data streams.
aws rds describe-db-instances --query 'DBInstances[].[DBInstanceIdentifier,DBInstanceStatus,Endpoint.Address]' --output tableList 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.jsonRun 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 UnblendedCostSpend for a date range, e.g. this month so far.
aws cloudformation describe-stacks --query 'Stacks[].[StackName,StackStatus]' --output tableList 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 · \dnInside psql: list databases · tables · a table's columns · schemas.
\x auto · \timing onReadable output for wide rows · show how long each query takes.
\copy t TO 'out.csv' CSV HEADERExport a table (or a query in parentheses) to a local CSV.
\copy t FROM 'in.csv' CSV HEADERLoad 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.dumpBack up · restore a database.
DuckDB (fast local SQL on files)
duckdbOpen 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.jsonPick fields out of JSON.
jq -r '.[] | [.id,.name] | @csv' data.jsonTurn a JSON array into CSV.
csvlook data.csv | less -SView a CSV as an aligned table (pip install csvkit).
csvstat data.csvPer-column stats: types, nulls, min and max.
column -s, -t < data.csv | less -SQuick table view with no install.
Python environments
python3 -m venv .venv && source .venv/bin/activateCreate and turn on a project virtual environment.
pip install -r requirements.txtInstall a project's dependencies.
pip freeze > requirements.txtSave exact installed versions.
uv venv · uv pip install pandasuv: a much faster venv and pip replacement.
python -m http.server 8000Serve the current folder over HTTP.
jupyter labStart notebooks in the browser.
Docker
docker ps -aList containers, including stopped ones.
docker compose up -d · docker compose downStart a stack in the background · stop and remove it.
docker logs -f <container>Follow a container's logs.
docker exec -it <container> bashOpen a shell inside a running container.
docker run --rm -p 5432:5432 -e POSTGRES_PASSWORD=pw postgres:16Throwaway local Postgres.
docker build -t app:dev .Build an image from the Dockerfile here.
docker system prune -aDestructive ·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> -- shShell into a pod.
kubectl port-forward svc/<svc> 8080:80Reach a cluster service on localhost:8080.
Spark, Airflow and dbt
spark-submit --master yarn --deploy-mode cluster job.pySubmit a PySpark job to a cluster.
pysparkInteractive 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 debugCheck dbt's connection and project setup.
dbt run --select model_name+Build a model and everything downstream of it.
dbt test · dbt buildRun data tests · run models and tests together.
dbt docs generate && dbt docs serveBrowse 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 fileChecksum a file to confirm a transfer arrived intact.
iconv -f latin1 -t utf-8 in.csv > out.csvFix text-encoding problems.
file data.csvDetect 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.