Software & Apps Linux Discover Your Directory With the pwd Command By Gary Newell Writer Gary Newell was a freelance contributor, application developer, and software tester with 20+ years in IT, working on Linux, UNIX, and Windows. our editorial process Gary Newell Updated December 11, 2019 Gaël Rognin/EyeEm/Getty Images Linux Switching from Windows Tweet Share Email One of the most important commands you will learn when using the Linux command line is the pwd command which stands for print working directory. This guide will show you how to use the pwd command and will show you the physical path to the directory you are working in and the logical directory you are working in. Find out Which Linux Directory You Are Currently In To find out which directory you are currently in run the following command: pwd The output for the pwd command will be something like this: /home/gary As you move around the system the working directory will change to reflect your current position within the file system. For example, if you use the cd command to navigate to the documents folder the pwd command will display the following: /home/gary/documents What Does pwd Show When You Navigate to a Symbolically Linked Folder For this part, we will set up a little scenario to explain the situation. Imagine you have a folder structure as follows: homegarydocumentsfolder1folder2 Now imagine you created a symbolic link to folder 2 as follows: ln -s /home/gary/documents/folder1 /home/gary/documents/accounts The folder tree would now look like this: homegarydocumentsfolder1folder2accounts The ls command shows the files and folders within a particular location: ls -lt If we ran the above command against our documents folder we would see that for accounts it would show something like this: accounts -> folder2 Symbolic links basically point to another location within the file system. Now imagine that you are in the documents folder and you used the cd command to move into the accounts folder. What do you think the output of pwd will be? If you guessed that it would show /home/gary/documents/accounts then you would be correct but if you ran the ls command against the accounts folder it is showing you the files within the folder2 folder. Look at the following command: pwd -P When you run the above command within a symbolically linked folder you will see the physical location which in our case is /home/gary/documents/folder2. To see the logical folder you can use the following command: pwd -L This would, in our case, show the same as pwd on its own which is /home/gary/documents/accounts. Depending on how pwd is compiled and set up on your system the pwd command may default to the physical path or may default to the logical path. Therefore it is a good habit to use the -P or -L switch (depending on which behavior you wish to see). Using the $PWD Variable You can view the current working directory by displaying the value of the $PWD variable. Simply use the following command: echo $PWD Display the Previous Working Directory If you want to view the previous working directory you can run the following command: echo $OLDPWD This will display the directory you were in before you moved to the current directory. Multiple Occurrences of pwd As mentioned earlier pwd may behave differently based on how it is setup. A good example of this is within Kubuntu Linux. The shell version of pwd which is used when you run pwd shows the logical working directory when you are within a symbolically linked folder. However, if you run the following command you will see that it shows the physical working directory when you are within a symbolically linked folder. /usr/bin/pwd This is obviously not very helpful because you are essentially running the same command but you are having the reverse result when run in a default mode. As mentioned earlier you probably want to get into the habit of using the -P and -L script. Summary There are only two further switches for the pwd command: pwd --version This displays the current version number for pwd. When run against the shell version of pwd this may not work but will work against the /bin/pwd. The other switch is as follows: pwd --help This displays the manual page to the terminal window Again this doesn't work for the shell version of pwd, only against the /bin/pwd version.