- List EC2 Instances:
function li() {
aws ec2 describe-instances \
| jq -r '.Reservations[].Instances[] | [(.Tags[]|select(.Key=="Name").Value),.InstanceId,.PrivateIpAddress,.VpcId,.State.Name,.LaunchTime] | @csv' \
| mlr --c2p --implicit-csv-header label Nmae,InstanceId,PrivateIpAddress,VpcId,State,LaunchTime then sort -f LaunchTime then cat
}function li() {
aws ec2 describe-instances \
$([[ -n ${instance_ids} ]] && echo --instance-ids ${instance_ids}) \
--query "
Reservations[].Instances[][
InstanceId,
InstanceType,
State.Name,
[Tags[?Key=='Name'].Value][0][0],
PublicIpAddress,
PrivateIpAddress,
Placement.AvailabilityZone,
VpcId
]" \
--output text |
grep -E -- "$filters" |
sort -k 4,4 |
align
}- Port forward over AWS SSM:
aws ssm start-session --target $INSTANCE_ID \
--document-name AWS-StartPortForwardingSession \
--parameters '{"portNumber":["80"],"localPortNumber":["9999"]}'- Convert video container type:
ffmpeg -i input.mkv -acodec copy -vcodec copy -f mp4 output.mp4
- Create gif from video:
ffmpeg -ss 61.0 -t 2.5 -i StickAround.mp4 -filter_complex \
"[0:v] fps=12,scale=480:-1,split [a][b];[a] palettegen [p];[b][p] paletteuse" SmallerStickAround.gif
- Show git commit of current Nix channel:
nix-instantiate --eval -E '(import <unstable> {}).lib.version'- List all resources used by a security group:
aws ec2 describe-network-interfaces --filters Name=group-id,Values=<group-id> --region <region> --output json- List all security groups used by all Lambas:
aws lambda list-functions | jq -c '.Functions[] | {FunctionArn, SecurityGroups: (.VpcConfig.SecurityGroupIds[]? // null) }'- Find what owns an unknown IP address in AWS account:
aws ec2 describe-network-interfaces --filters "Name=addresses.private-ip-address,Values=ip.add.re.ss"- Monitor port for any listening applications
sudo lsof -r 1 -sTCP:LISTEN -i:443- List all AWS Secrets as Markdown
aws secretsmanager list-secrets | \
jq -r '.SecretList[] | [.Name, .ARN, .Description] | @csv' | \
mlr --icsv --omd label Secret,ARN,Description then sort -f Secret
- Find summary time of all videos
find . -type f -exec mediainfo --Inform="General;%Duration%" "{}" \; 2>/dev/null \
| awk '{s+=$1/1000} END {h=s/3600; s=s%3600; printf "%.2d:%.2d\n", int(h), int(s/60)}'
- Shrink GIF Size:
gifsicle -O3 --lossy=80 gifimage1.gif -o new-gifimage1.gif
- Multiline grep with ripgrep:
https://til.hashrocket.com/posts/9zneks2cbv-multiline-matches-with-ripgrep-rg
rg --multiline "(?s)aws_s3_bucket.*bucket-name-here"- List only file resolution with ffprobe:
ffprobe -v error -select_streams v:0 -show_entries format=filename:stream=width,height,avg_frame_rate -of csv=p=0 file.mp4
find . -type f \( -iname '*.wmv' -o -iname '*.mp4' -o -iname '*.avi' -o -iname '*.mkv' -o -iname '*.mov' -o -iname '*.mpg' \) \
-exec ffprobe -v error -select_streams v:0 -show_entries format=filename:stream=width,height,avg_frame_rate \
-of csv=p=0 {} -print_format json \; | \
mlr --json --opprint flatten then cut -x -f programs then rename \
streams.1.width,width,streams.1.height,height,streams.1.avg_frame_rate,framerate,format.filename,filename \
then sort -f filename \
then put '$framerate = splita($framerate, "/"); $framerate = $framerate[1] / $framerate[2]; $framerate = fmtnum($framerate, "%.2f")'
- Rsync only file timestamps from remote host:
rsync -vrti --size-only --existing src:/a /a- Open file in Windows from WSL:
cmd.exe /C start <file>- Find latest CentOS 6 /7 AMIs on the marketplace:
# CentOS 6
aws --region us-east-1 ec2 describe-images \
--owners 'aws-marketplace' \
--filters 'Name=product-code,Values=6x5jmcajty9edm3f211pqjfn2' \
--query 'sort_by(Images, &CreationDate)[-1].[ImageId]' \
--output 'text'
# CentOS 7
aws --region us-east-1 ec2 describe-images \
--owners 'aws-marketplace' \
--filters 'Name=product-code,Values=aw0evgkw8e5c1q413zgy5pjce' \
--query 'sort_by(Images, &CreationDate)[-1].[ImageId]' \
--output 'text'- Add AWS security group rule with description:
aws ec2 authorize-security-group-ingress --group-id sg-XXX \
--ip-permissions \
'FromPort=443,ToPort=443,IpProtocol=tcp,IpRanges=[{CidrIp="6.6.6.6/32",Description="group test name here"}]'- Read multiple lines in bash
$ while read -r FILE; do
> read -r VERSION
> echo "file: $FILE VERSION: $VERSION"
> done < out- Install helm chart without tiller:
helm template --namespace <namespace> --name <name> . -f values.yml | kubectl apply -f -- Mass delete s3 keys:
cat file-of-keys | xargs -P8 -n1000 bash -c 'aws s3api delete-objects --bucket MY_BUCKET_NAME \
--delete "Objects=[$(printf "{Key=%s}," "$@")],Quiet=true"' _- Run AWS ssm command on remote host:
aws ssm send-command --instance-ids "i-ID" --document-name "AWS-RunShellScript" \
--parameters commands='find / -ls' \
--output-s3-bucket-name s3-bucket-name- Find largest git objects in repository:
git rev-list --objects --all \
| git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)' \
| sed -n 's/^blob //p' \
| sort --numeric-sort --key=2 \
| cut -c 1-12,41- \
| $(command -v gnumfmt || echo numfmt) --field=2 --to=iec-i --suffix=B --padding=7 --round=nearest- Split input into files based on field name:
awk -F: '{print > $4 ".txt" }' /etc/passwd- Rename files with parallel
find . -type f -name '*.mkv'| parallel mv -i {} {//}/{//}.mkv- Launch AWS instance with awless:
awless create instance distro=canonical:ubuntu type=t2.medium keypair=keyname subnet=@subnet-name name=instance-name- Edit chef data bag locally
knife solo data bag edit credentials passwords \
--secret-file test/integration/data_bags/encrypted_data_bag_secret --data-bag-path test/integration/data_bags- Delete until fourth field. Useful when 4th field item has spaces.
awk '{print substr($0, index($0, $4))}'- Replace newlines with
\n:
sed -E ':a;N;$!ba;s/\r{0,1}\n/\\n/g' file- Replace newlines with '\n' in Ruby:
ruby -e 'p ARGF.read' file- Tcpdump to watch nicely formatted HTTP requests with headers coming in via network to the local server
sudo stdbuf -oL -eL /usr/sbin/tcpdump -A -s 10240 "tcp port 80 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)" | egrep -a --line-buffered ".+(GET |HTTP\/|POST )|^[A-Za-z0-9-]+: " | perl -nle 'BEGIN{$|=1} { s/.*?(GET |HTTP\/[0-9.]* |POST )/\n$1/g; print }'- Show SSL Certificate
echo | openssl s_client -showcerts -servername host.com \
-connect host:443 2>/dev/null | openssl x509 -inform pem -noout -text- Show SSL Expiration Date
echo | openssl s_client -showcerts -servername host.com \
-connect host:443 2>/dev/null | openssl x509 -inform pem -noout -dates- Delete old snaps
$ echo snap list --all | while read snapname ver rev trk pub notes; do if [[ $notes = *disabled* ]]; then snap remove "$snapname" --revision="$rev"; fi; done