Unix Spells


Check Network Utilization

sudo iftop -B

Process Substitution

Creating a named pipe is done in fish with the psub command as follows:

diff (sort a.txt | psub) (sort b.txt | psub)

References: man psub

Extract and Pretty Print Stack Trace from Logback Logs

cat tmp | jq ".stack_trace" | xargs printf


Tips and tricks with less

Display ANSI color codes

less -R

Display Line Numbers

less -N

All these less commands can be passed in as args, or when already in less. Also, some of the search and movement syntax of vim works in less as well.


Direct Usage

To make the output legible, as well as manageable, make sure to

  1. specify the port you care about
  2. use the -XX and -i flags to get ascii output next to the binary
sudo tcpdump -XX -i eth0 port 44380 > /tmp/dump

Pretty Print PCAP file

If you have an existing PCAP file (for example, from wireshark), you can run it through tcpdump to pretty print the contents as follows:

tcpdump -qns 0 -X -r file.pcap


List files with specific extension and perform command on them

# In this case, list video files and for each one, extract metadata
find . -type f \( -iname \*.mkv -o -iname \*.mp4 -o -iname \*.avi \) -print0 | while IFS= read -r -d '' file; do
  ffprobe -v quiet -print_format json -show_format -show_streams $file;
done > ~/video_metadata.json