Skip to content

Instantly share code, notes, and snippets.

@beli-sk
Last active July 18, 2017 14:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beli-sk/c2be754927056644dd6e to your computer and use it in GitHub Desktop.
Save beli-sk/c2be754927056644dd6e to your computer and use it in GitHub Desktop.
Useful CLI one-liners (Linux)
# Number of open file descriptors per process (replace 'httpd' with process name)
lsof -p $( echo `ps -o pid= -C httpd` | tr ' ' ',' ) | awk '{ print $2 }' | uniq -c
# Show swap usage per process, >=1000 kB
cat /proc/*/status | egrep -B30 '^VmSwap:[[:space:]]+[[:digit:]]{4,}' | egrep '^Name|^Pid|^VmSwap'
# generate password
head -c12 /dev/urandom | base64 | tr '+/' '_-' | tr -d '='
# days to web server certificate expiry
echo $(( ( $( date -d "`openssl s_client -servername example.com -connect example.com:443 < /dev/null 2> /dev/null | openssl x509 -noout -enddate | grep notAfter | cut -d= -f2`" '+%s') - `date '+%s'` ) / 60 / 60 / 24 ))
# list virtio block devices with PCI IDs (not exactly one-liner, but useful anyway)
for dev in /sys/bus/virtio/drivers/virtio_blk/virtio* ; do
echo $( readlink "$dev" | sed -r 's#.*/(pci.*)#\1#' ) $( ls "${dev}/block" )
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment