Skip to content

Instantly share code, notes, and snippets.

@davit
Last active January 1, 2016 18:09
Show Gist options
  • Save davit/8182308 to your computer and use it in GitHub Desktop.
Save davit/8182308 to your computer and use it in GitHub Desktop.
A linux script for finding a port number according to a service (e.g. http: 80)
#!/bin/bash
# This one displays both service and port number colored in red (most likely):
egrep --color -o -m 1 '^'$1' *[0-9]+' /etc/services
# This one displays only the port number:
egrep -o -m 1 '^'$1'\s+[0-9]+' /etc/services | grep -P -o '\d+$'
# or
egrep -o -m 1 '^ftp\s+[0-9]+' /etc/services | egrep -o '[1-9]+$'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment