Forked from gerrard00/pwdx_and_portpwdx_for_mac.bash
Created
November 1, 2018 10:11
-
-
Save cuiwm/ea6b13930d1349895613b4d399308ecd to your computer and use it in GitHub Desktop.
pwdx for mac. Usage: pwx pid also portpwdx that finds the pwd for the process that owns a port. Usage: portpwdx port
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function pwdx { | |
| # note: NF is the number of columns, so $NF gives us the last column | |
| lsof -a -p $1 -d cwd -n | tail -1 | awk '{print $1, "\t", $NF}' | |
| } | |
| function portpwdx { | |
| # pid=$(lsof -i :5858 | tail -1 | perl -pe 's/[^\s]+\s+([^\s]+)\s.*/$1/') | |
| pid=$(lsof -i :$1 | tail -1 | perl -pe 's/[^\s]+\s+([^\s]+)\s.*/$1/') | |
| if [[ ! -z $pid ]]; then | |
| echo $pid | |
| pwdx $pid | |
| return 0 | |
| else | |
| echo "No process listening to port $1" | |
| return -1 | |
| fi | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment