Skip to content

Instantly share code, notes, and snippets.

@tasermonkey
Last active April 4, 2023 14:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tasermonkey/10648817 to your computer and use it in GitHub Desktop.
Save tasermonkey/10648817 to your computer and use it in GitHub Desktop.
Listening
Mac OSX:
listening () {
lsof -Pni | grep '(LISTEN)' | awk 'BEGIN {printf "%-15s %5s %21s\n", "Command", "PID", "PORT"} {printf "%-15s %5s %21s\n", $1,$2,$9}'
}
Linux (if you want non-you processes that are listening):
listening () {
sudo lsof -Pni | grep '(LISTEN)' | awk 'BEGIN {printf "%-15s %5s %21s\n", "Command", "PID", "PORT"} {printf "%-15s %5s %21s\n", $1,$2,$9}'
}
For linux you can copy the function into a new file called(or any other name): /etc/profile.d/listening.sh.
@tasermonkey
Copy link
Author

Example output:
$ listening

Command           PID                  PORT
Growl             430       127.0.0.1:23053
Growl             430           [::1]:23053
Amazon           1209        127.0.0.1:4750
java            19041               *:54078
java            19041                *:2181
idea            64118        127.0.0.1:6942
idea            64118               *:61749
idea            64118               *:61658
idea            64118       127.0.0.1:63342
idea            64118                *:2864
nginx           69686                *:3100
VBoxHeadl       71345        127.0.0.1:2222
GoogleTal       76152       127.0.0.1:60246
GoogleTal       76152       127.0.0.1:60247
Dropbox         81788               *:17500
Dropbox         81788       127.0.0.1:26165
java            84533                *:3001

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment