Sam’s Command Line Cheatsheet

Misc Command Line

Server benchmark
ab -n 10000 -c 20 -H "Host: test3.com" http://mysite
SSH with custom key
ssh -i ~/.ssh/id_custom root@ipaddr
Extract tar file
tar -xvzf zipped_file target_folder
iOS screen recording
xcrun simctl io booted recordVideo ~/Downloads/screen.mov

cURL

GET with bearer auth
curl -H 'Bearer TOKEN' "https://mysite"
POST without data
curl 'http://myurl' -X POST
POST without data
curl 'http://myurl' -X POST
PATCH with data and custom header
curl -v -H "X-AUTH-KEY: APIKEY" -H "Content-Type: application/json" -X PATCH --data '{"hello":"world”}' "http://mysite"

Kubernetes

Follow component logs
kubectl logs --tail 200 -f -lcomponent=mycomponent
Find env in deployment
kubectl exec -it deploy/mydeploy -- env | grep SEARCH
Start shell in pod
kubectl exec -it -n default postgresql-0 -- /bin/bash

Docker

Start bash shell in container
sudo docker exec -it CONTAINER bash
Follow container logs
sudo docker logs -f -n 200 CONTAINER
Run local postgres
sudo docker run --rm --name postgres-dev -p 5432:5432 -e POSTGRES_PASSWORD=password -d postgres
Run local Redis
sudo docker run --name redis -d -p 6379:6379 redis:7

Postgres

Dump zipped database
pg_dump -Fc -U postgres -d mydb > db.dump
Restore zipped database
pg_restore -U postgres -d mydb db.dump
Postgres CLI
psql -U postgres -h host -p 5432 -d mydb

ffmpeg

Simple format conversion
ffmpeg -i recording.mov -r 24 recording.mp4
Convert screen capture to mp4
ffmpeg -fflags +genpts -i screen-capture.webm -r 24 screen.mp4
Crop and trim screen capture
ffmpeg -fflags +genpts -i screen-capture.webm -r 24 -filter:v "crop=1000:600:0:0" -ss 00:00:03 -to 00:00:12 screen.mp4
GIF to mp4
ffmpeg -i coding.gif -vf "crop=trunc(iw/2)*2:trunc(ih/2)*2" -b:v 0 -crf 25 -f mp4 -vcodec libx264 -pix_fmt yuv420p coding.mp4
GIF to webm
ffmpeg -i coding.gif -c vp9 -b:v 0 -crf 41 coding.webm
Stack videos horizontally
ffmpeg -i left.mp4 -i right.mp4 -filter_complex hstack output.mp4
Get audio from mp4
ffmpeg -i input.m4a -c:v copy -c:a libmp3lame -q:a 4 output.mp3