The pwd command in Linux is short for present working directory. When it comes to Linux commands, this has to be one of the simplest. It’s only function is to print the present working directory of your terminal. It comes in handy when you’re not exactly sure what directory you’re in, or when you need to pass the present working directory inside of a Bash script, for example.
In this tutorial, you’ll learn how to use the pwd command in Linux through examples. Follow along to see how it works.
In this tutorial you will learn:
- How to use the pwd command on Linux
|Category||Requirements, Conventions or Software Version Used|
|System||Any Linux distro|
|Other||Privileged access to your Linux system as root or via the
|Conventions||# – requires given linux commands to be executed with root privileges either directly as a root user or by use of
$ – requires given linux commands to be executed as a regular non-privileged user
Frequently Used Options
The pwd command in Linux is used to print the present working directory. Another command which can do the same thing is dirs. Check out the examples below to see how the command works.
pwd command in Linux Examples
- Simply type pwd into your terminal, and the command will output the absolute path of your present working directory.
$ pwd /home/linuxconfig
In this example, the command has indicated that our present working directory is
- There are only two different options available for the pwd command. The
-Pwill avoid listing symbolic links, and instead give you an absolute path. And the
-Loption will list symbolic links, if you have used one to navigate to a particular directory. As an example, we have made a symbolic link to the
/var/logdirectory on our system. Watch what happens when we use each of these two options.
$ pwd -P /var/log $ pwd -L /home/linuxconfig/myfile
You can always use the man command to read more about the pwd command and its official documentation. Click the previous link to see how to open the manual pages for any command on a Linux system.
In this tutorial, we learned all about the pwd command on Linux which is one of the simplest commands you will ever learn, and yet it comes in handy more than you might think. If you ever feel lost in your Linux terminal, the pwd command is easy to remember and will always get you reoriented by showing what directory you’re in.