Linux pwd command - Know Your Current Working Directory

January 10, 2014 | By in LINUX COMMANDS, LINUX HOWTO
| Reply More

Where you are inside a deep directory, sometimes you may want to know where exactly you are. With this pwd command, you can do it.

What is pwd

Pwd is a command to print name of current / working directory. When we are “lost” into a deep directory, we can always reveal where we are.

How to use it

Since pwd command is intended to only print name of current / working directory, pwd does not have a lot of parameter to add. To use it, you just can type :

$ pwd

And it will print where you are. For a shell like bash, sometimes this information already print after host-name. Take a look at below picture.

Pwd in bash

As you can see above, the /lib/udev/rules.d is printed a hostname. When we type pwd, it will print /lib/udev/rules.d again. But when you are using another shell such as csh, pwd may help you to tell where are you. Here’s a sample of it.

% pwd

Pwd in csh shell

Print physical directory avoid all symlinks

When you are in directory which is a symbolic links to another directory, you will find that pwd will print the alias / symbolic links to it. To print the real directory name, we can use -P parameter.

$ pwd -P

Physical pwd

Physicall pwd

Physical pwd

At the screenshot above, we are change the directory to PlayOnLinux’s virtual drives. This directory is located in /home/pungki and its a symbolic link to wineprefix directory. When we do pwd command, the shell return /home/pungki/PlayOnLinux’s virtual drives. But if we add -P parameter, the we will know that the real directory is /home/pungki/.PlayOnLinux’s/wineprefix

Reveal which pwd

On bash shell, pwd may already built-in inside it. To know it, we can use this command :

$ type -a pwd

pwd type

You see that there are two pwd’s. When you use pwd, you may use the built-in pwd command on your shell. This pwd will override the original pwd. Here’s a sample.

Symlink pwd

On the screenshot above, we are now inside /home/pungki./PlayOnLinux/wineprefix. When we use /bin/pwd, it will return the real name of current directory. But when we add -L parameter, it will return a symbolic link name of current directory.

This -L parameter output the same result if we just type pwd, which use built-in shell pwd.

Print pwd version

To print pwd version, we can use --version parameter. But for bash shell, we need to use /bin/pwd instead of pwd. Otherwise, it will return an error message.

pwd version


pwd may help you to know where your current directory when your bash don’t print it directly on command prompt. As usual, you can always type man pwd to explore pwd usage more detail.


Share This :

Free Linux Ebook to Download

Leave a Reply

Commenting Policy:
Promotion of your products ? Comment gets deleted.
All comments are subject to moderation.