Created
November 15, 2016 20:44
-
-
Save danielnegri/2c70bf96ea9cffd46a19caff08a85172 to your computer and use it in GitHub Desktop.
Report current working directory of a process by 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
| # Report current working directory of a process by port | |
| function pwdx { | |
| # lsof -a -p $1 -d cwd -n | tail -1 | awk '{print $NF}' | |
| lsof -a -p $1 -d cwd -n | |
| } | |
| portpwdx () { | |
| 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