From DN Wiki
Revision as of 22:23, 1 April 2021 by Dave (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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


Find the subnet given IP and mask or CIDR

ipcalc -n | grep Network | awk '{print $2}'

Pad an IP to make it sortable

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

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`
  • $(ping -c10 -W2
  • for x in 0{1..9} {10..12} ; do mkdir 2016/2016-$x
  • while read LINE; do echo $LINE; done < FILE

Ping Sweep with For Loop

From: Linux Ping Sweep

for i in {1..254} ;do (ping -c 1 192.168.1.$i | grep "bytes from" &) ;done

What this does is a for loop from 1 to 254, $i takes the value of the current iteration so in the first one it will be 1 then 2, 3… and so on, then we tell it to call the ping command with the -c option which means only ping once otherwise it would ping forever after that we pipe the output to grep so we only see the hosts that actually responded and the & at the end send it to the background so it will launch all the pings in parallel. If we only want the ip address and not the whole line we can further filter this using cut.


To reload after editing...

bind -f  ~/.inputrc

My usual stuff

# Make auto-complete cycle through options instead of listing them all
TAB: menu-complete
# Make shift tab reverse the above
"\e[Z": "\e-1\C-i"
# Use up and down arrow to search command history. Invaluable!
"\e[A": history-search-backward
"\e[B": history-search-forward
# Use Control-g to keep a command in history without executing
"\C-g": "\C-a history -s \C-j"