How to change directory to a directory where a job(PID) is running in linux?

Viewed 287

I can check where a job is running with

pwdx <PID>

I want to change directory into that specific directory. As of now, I just copy the directory name and 'cd' into it. What I want is a compact way of doing it. For instance, I want something like:

cd pwdx <PID>

Sorry for being sloppy!

1 Answers

This removes the PID from the output of pwdx and the result becomes the argument to cd.

cd "$(pwdx <PID> | awk '{print $2}')"

or create a function:

pidcd () {
    cd "$(pwdx "$1" | awk '{print $2}')"
}
Related