One-liners

From Unix Wiki
Jump to: navigation, search

Linux

Check what process read or write for last 10 secs. Adjust values accordingly.

watch -n 10 "grep -e read -e write /proc/*/io | awk '\$2 >= 20000000' | sdiff --suppress-common-lines - /tmp/stat.log ;\
 grep -e read -e write /proc/*/io | awk '\$2 >= 20000000' > /tmp/stat.log"

NGINX

Self signed certificate:

openssl req -new -x509 -nodes -out cert.pem -keyout cert.key

SED

Two-line match

Next line will match anything in two lines.

sed -n '/#CNAME \(.*\)/{N;s/#CNAME \(.*\)\nHost \(.*\)$/\1 \2/p;}'
  1. Search for '#CNAME' pattern;
  2. N; will append next line to pattern space;
  3. \n - Next line;
  4. \(.*\) stores match to variable;
  5. \1 - prints variable;

Hex dump output

| xxd -g 1 -c 1

Print between html tags

sed -n 's/.*>\(.*\)<.*/\1/p'