Read in 3 minutes

last updated 

Determine Your Current Working Directory in Linux Using the pwd Command

In this tutorial, we will show you how to use the pwd command to determine your current working directory.

What is Current Working Directory

The current working directory is the directory in which the user is currently working in. Each time you interact with your command prompt, you are working within a directory.

By default, when you logging into your Linux system your current working directory is set to your home directory. To change the working directory use the cd command. For example, to change the current working directory to /tmp you would type:

cd /tmp

On some Linux distributions, or if you have a customized bash or zsh prompt, the path to your current working directory may be shown in the shell prompt.

pwd Command

The pwd command stands for print working directory. It one of the most basic and frequently used commands in Linux. When executed the command will print the complete path of your current working directory.

pwd is a shell builtin in most modern shells such as bash and zsh. Its behavior is slightly different than the standalone /bin/pwd executable. You can use the type -a to display all locations containing the pwd.

type -a pwd
pwd is a shell builtin
pwd is /bin/pwd

As you can see from the output below, the shell builtin has priority over the standalone executable and it will be used whenever you type pwd. If you want to use the standalone pwd command you’ll need to use the full path to the binary /bin/pwd

How to Find your Current Working Directory

To find out what directory you are currently in, type pwd in your terminal:

pwd

The command will display the path of your current working directory:

/home/linuxize

What the command does is printing the PWD environment variable. You will get the same output if you type:

echo $PWD
/home/linuxize

The pwd command can accept only two arguments:

  • -L (--logical) - Display the value of the $PWD variable. By default, pwd behaves as if -L option is specified.
  • -P (--physical) - Display the physical directory, without any symbolic links

To better illustrate how the -P option works we will create a directory and a symlink that will point to the directory:

mkdir /tmp/directory
ln -s /tmp/directory /tmp/symlink

Now if you navigate to the /tmp/symlink directory and you type pwd in your terminal:

/tmp/symlink
pwd

The output will show that your current working directory is /tmp/symlink.

/tmp/symlink

If you run the same command using the -P option:

pwd -P

Your current working directory is /tmp/directory, the directory to which the symlink points to.

/tmp/directory

Conclusion

By now you should have a good understanding of what is the current working directory and how to use the pwd command to find your current working directory.

If you have any question or feedback feel free to leave a comment.