Skip to content.
Joe Heaton's Webzone
🥐 ☕
Online since 2011

Useful Unixisms

Here’s a list of useful piped commands or just commands for which I need a refresher on which arguments to use. For example, using Awk to print between two known lines, or seleting a line in sed are good examples of infrequently used commands which are really useful.

generate 8 character alphanumeric string

< /dev/urandom tr -dc A-Za-z0-9 | head -c8; echo

awk '/A/,/B/{ print FILENAME, $1}' FILES

find new files

find . -printf "%T+\t%p\n" | sort

delete lines until string

sed -i '0,/^STRING$/d' FILE

delete lines X until Y

sed -i 'X,Yd' FILE

read a process' stdout

strace -p17025 -s999 -e read 2>&1

listening ports and their process

netstat -tulpn

-t(tcp) -u(udp) -l(listening only) -p(pid) -n(no port names)

tcpdump http(80)

/usr/sbin/tcpdump -i eth0 -n 'port 80'

watch, highlight any changes permanently

watch -d=cumulative -n1 date

awk '{ print substr($0, index($2,$5)) }'

cut -d, -f2-5

awk '{l++}{s+=$1}END{print s/l}'

find value in column

awk '$3 == "text" {print}' awk '$3 ~ /regex/ {print}'

pass an arg to 8 processes until arguments exhausted

find . | xargs -P8 -n1 -I{} cp -v {} {}.backup

Settings!