Bash

From DN Wiki
Jump to navigation Jump to search

Random Linux stuff that I'm tired of looking up.

HowTo

Find the subnet given IP and mask or CIDR

ipcalc -n 172.16.16.113 255.255.255.252 | grep Network | awk '{print $2}'
172.16.16.112/30

Pad an IP to make it sortable

echo 172.16.16.112/30 | awk -F '[./]' '{printf "%03d.%03d.%03d.%03d/%03d\n", $1,$2,$3,$4,$5}'
172.016.016.112/030
Date

My preferred date/time format.

  • echo test >> `date +'%Y-%m-%d_%H:%M:%S'`.txt
Command Substitution

Backticks or the other thing I never remember.

  • `ping -c10 -W2 1.1.1.1`
  • $(ping -c10 -W2 1.1.1.1)
Loops
  • for x in 0{1..9} {10..12} ; do mkdir 2016/2016-$x
  • while read LINE; do echo $LINE; done < FILE