Overview
Accurately verifying your current location when working in the Linux terminal is fundamental for file management and command execution. This guide introduces everything from the basic usage of the pwd command to verifying absolute paths, resolving symbolic links (-P, -L options), and tips for utilizing it in shell scripts in an easy-to-understand manner.
Basic Usage of pwd and Checking the Current Working Directory
Run the mkdir -p ~/pwd-tutorial/sample-dir command to create a dedicated directory for practicing the pwd command.

Run the cd ~/pwd-tutorial/sample-dir command to change your working directory to the newly created practice directory.

The pwd (Print Working Directory) command prints the absolute path of the current terminal’s working directory to the screen.
Looking at the execution result, you can confirm that the current location is accurately displayed as the absolute path /root/pwd-tutorial/sample-dir.
⚙️ [Key Options]
-L : Displays the logical working directory path, including symbolic links (default).-P : Resolves all symbolic links and prints the actual physical directory path.--help : Displays command usage and help information.--version : Displays the version information of the command.

Distinguishing Symbolic Link Paths from Physical Paths (-L vs -P)
Run the mkdir -p ~/pwd-tutorial/real-storage command to prepare an actual directory for the symbolic link comparison exercise.

Run the ln -sfn ~/pwd-tutorial/real-storage ~/pwd-tutorial/link-storage command to create a symbolic link pointing to the created physical directory.

To verify the practice environment, run the cd ~/pwd-tutorial/link-storage command to move into the created symbolic link directory.

The pwd -L command displays the logical working path including symbolic links.
You can verify from the execution result that the symbolic link path is reflected and displayed as /root/pwd-tutorial/real-storage.

The pwd -P command resolves all symbolic links and prints the physical disk path that actually exists.
The execution result accurately displays /root/pwd-tutorial/real-storage, which is the actual target directory path of the symbolic link.

Leveraging the $PWD Environment Variable and Combining with the cd Command
To practice using environment variables, navigate to the practice directory created earlier by executing cd ~/pwd-tutorial/sample-dir.

The echo "현재 위치는: $PWD" command displays the value of the $PWD environment variable, which is automatically maintained by the shell.
You can verify that the absolute path of the current working directory, /root/pwd-tutorial/sample-dir, is properly printed in the execution result.

Run the cd .. command to move to the parent directory in order to test the environment variable that tracks the previous directory path.

The echo "이전 디렉터리는: $OLDPWD" command displays the value of the $OLDPWD environment variable, which retains the path of the previous working directory.
You can confirm from the execution result that the directory path worked on just moments ago, /root/pwd-tutorial/sample-dir, is accurately displayed.

Run the pwd command to check the current working directory after moving up to the parent directory.
You can verify from the execution result that the current location has properly changed to the absolute path /root/pwd-tutorial.

Practice Environment Cleanup and Practical Scripting Tips
Run echo 'CURRENT_DIR=$(pwd -P); echo "실행 경로: $CURRENT_DIR"' > ~/pwd-tutorial/run.sh to write a practical example script that extracts the actual physical path using pwd -P.

Execute bash ~/pwd-tutorial/run.sh to run the created shell script.
In the execution result, you can confirm that the physical absolute path is resolved inside the script and successfully printed in the format /root/pwd-tutorial.

After finishing all practices, run the rm -rf ~/pwd-tutorial command to clean up all tutorial directories and files created.

So far, we have covered everything from the basic usage of the pwd command for checking the current working path in Linux to options for resolving symbolic links.
When working in a terminal environment, be sure to utilize the appropriate options depending on the situation to avoid confusion about your current location.