Table of Contents generated with DocToc

System administration

Find PID using a given port number

lsof -i :6234

Find disk usage per directory

find . -maxdepth 1 -type d -exec du -sh {} \;

or

find . -maxdepth 1 -type d | xargs du -sh

Delete all files more than x days old

find /path/to/directory/ -mindepth 1 -mtime +5 -delete

Delete everything except files with given extension

$ find . ! -name "*.jar" | xargs rm -rf

Measure response time with curl

$ curl -o /dev/null -s -w %{time_total} http://www.example.com/

Utilities

SSH tunnel - forward traffic from a specific localhost port to a specific remote host and port

ssh -L <localhost_port>:<remote_host>:<remote_port> <username>@<tunnel_server>

SSH tunnel - forward traffic from a specific localhost port to remote host - can also be used to setup SOCS proxy

ssh -D <localhost_port> -C -q -N <username>@<tunnel_server>

Download file using curl

$ curl -O <url>

Upload file using curl

$ curl --verbose -F 'file=@"/tmp/myFile.txt"' http://localhost:3000/api/myFileEndpoint

Rename all files in a directory with sequential numbers

a=1
for i in *.jpg; do
  new=$(printf "erg-%02d.jpg" "$a") #04 pad to length of 4
  mv -i -- "$i" "$new"
  let a=a+1
done

Simple load testing shell script

Measures time in seconds

#!/bin/bash

echo "fastlyTime,awsGatewayTime"

while true
do
  fastlyTime=`curl -o /dev/null -s -w %{time_total} -H 'X-Api-Key: bla' https://round-trippa.ft.com/callback`
  sleep 1
  awsGatewayTime=`curl -o /dev/null -s -w %{time_total} -H 'X-Api-Key: bla' https://round-trippa-gw-eu-west-1-prod.memb.ft.com/callback`
  sleep 1
  echo "${fastlyTime},${awsGatewayTime}" >> responsetimes.log
done

CentOS

Manage network interfaces

$ nmtui

Ubuntu

mkdir $HOME/Shared
/usr/bin/vmhgfs-fuse -o auto_unmount .host:/ $HOME/Shared

AWS CLI

S3 copy/download

aws s3 cp s3://<bucket-name>/<path-to-file> /tmp/. --region=eu-central-1

S3 upload object

 aws s3 cp /Users/anuragkapur/Desktop/hello-world.txt s3://<bucket-name>/ --profile <cli-credentials-profile-name>