You changed directory through a path containing a symbolic link.
Print the physical absolute path with the link resolved.
Which command is appropriate?
pwd -P prints a physical path with symbolic links resolved. pwd -L preserves the logical path tracked by the shell.
Detailed explanation
pwd -LIncorrect. -L requests the logical path and can retain the symbolic-link component.
Incorrect. -L requests the logical path and can retain the symbolic-link component.
pwd -PCorrect. -P resolves links and prints the physical directory.
Correct. -P resolves links and prints the physical directory.
echo "$PWD"Incorrect. $PWD normally represents the logical shell path.
Incorrect. $PWD normally represents the logical shell path.
uname -pIncorrect. uname -p reports a processor-related value, not the working directory.
Incorrect. uname -p reports a processor-related value, not the working directory.
Try it yourself
An example you can run in a temporary verification environment.
LAB_DIR=$(mktemp -d); mkdir "$LAB_DIR/real"; ln -s real "$LAB_DIR/link"
( cd "$LAB_DIR/link"; pwd -P )
rm -r "$LAB_DIR"Expected result
末尾が/realの絶対パスKey points
- pwd -P
- pwd -L
- Symbolic-link resolution
Notes
- Environment: Bash 5.2 / GNU coreutils 9.x
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.