Skip to content

Instantly share code, notes, and snippets.

@gavvvr
Created April 2, 2020 13:49
Show Gist options
  • Save gavvvr/0afa07bc52d8bef61c6d2ef807bc0579 to your computer and use it in GitHub Desktop.
Save gavvvr/0afa07bc52d8bef61c6d2ef807bc0579 to your computer and use it in GitHub Desktop.
netstat with full command running an associated process
netstat -antp 2>&1 | sort -k7,7 -k 6,6| {
while IFS= read -r line
do p="$(sed -En 's/^.*( [0-9]+)\/[^ ]*.*/\1/gp'<<<"$line")";
[ "$p" == "" ] || p=" ## $(ps -p $p -o cmd=)";
echo "$line"$p;
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment