How to use PWD Command in Linux
In this article, we will show you how to determine your current working directory using the pwd
command.
What is the 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 log 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
If you have a customized bash
or zsh
prompt, the path to the current working directory may be shown in the shell prompt.
user@host:/tmp#
pwd Command
The pwd
command stands for print working directory. It is one of the most basic and frequently used commands in Linux. When invoked the command prints the complete path of the 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
command to display all locations containing 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 is used whenever you type pwd
. If you want to use the standalone pwd binary type the full path to the file /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 output will look something like this:
OUTPUT
/home/reconshell
What the pwd
does is printing the PWD
environment variable .
You will get the same output if you type:
$ echo $PWD
OUTPUT
/home/reconshell
The pwd
command can accept only two arguments:
-L
(--logical
) – Do not resolve symlinks.-P
(--physical
) – Display the physical directory, without any symbolic links.
By default, id no option is used, pwd
behaves as if -L
option is specified.
To better illustrate how the -P
option works, let’s create a directory and symlink pointing to the directory:
$ mkdir /tmp/directoryln -s /tmp/directory /tmp/symlink
Now if you navigate to the /tmp/symlink
directory and you type pwd
in your terminal:
$ pwd
The output will show that your current working directory is /tmp/symlink
:
OUTPUT
/tmp/symlink
If you run the same command using the -P
option:
$ pwd -P
The command will print the directory to which the symlink points to:
OUTPUT
/tmp/directory
Conclusion
The current working directory is the directory from which you invoke commands in your terminal.The pwd
command is used to display the current working directory.
If you have any questions or feedback, feel free to leave a comment.
Leave a Reply