Cheat Sheets

  • bash -

    Run command in a loop endlessly

    while :; do sleep 5; echo "Hello"; done

    Run command a set number of times

    for i in {1..10}; do sleep 5; done

    Another way, this time pushing the output to a file and then sorting/inspecting the output.

  • bpftrace -

    bpftrace is kind of awesome. It lets you basically run event-driven logic at various “attachment points” in Linux, either in kernel or user space (depending on what your kernel was built with support for).

  • git -
    • git reflog very useful when undoing mistakes like accidental git checkout a change, hard resets, or bad rebases
    • git pull --rebase - I often check out others’ branches so I can reproduce something they’re looking at locally. Of course, they’re making changes all the time so I’ll need to pull those changes down, and I don’t want any changes I’ve made to result in merge commits etc - so this is preferred in this case.
  • jq -

    Filter an array of strings

    cat pp.json | jq '.p_cfg[] | . as $network | .networks[] | select(contains("192.168.100")) | $network.upstreams'

    Get key value out of consul kv export file

  • lsof -

    View files open by PID (using pgrep in subcommand for convenience):

    lsof -p $(pgrep -f "python3 sock_stream_server.py")

    View sockets by port or address

  • pwru -

    Not typically installed by default - find binaries here

  • ss -

    ss manpage

    Generally ss is viewed as the better, more modern successor to netstat - prefer using ss for inspecting local sockets