Before we begin talking about the Current Working Directory, let's briefly understand - What is the Current Working Directory?
The user's current working directory is the location where he or she is now working. You're operating in a directory every time you interact with your command prompt.
Your current working directory is set to your home directory by default when you connect to your Linux system. The
cd command is used to change the working directory.
In this tutorial, you will learn to use
pwd command in Linux. We will also address a few FAQs on pwd Command in Linux (Current Working Directory).
To change the current working directory to
/tmp, for example, type:
The path to the current working directory may be displayed in the shell prompt if you have customized
pwd command is used to print the current working directory. It's one of Linux's most fundamental and commonly used commands. When the command is run, it prints the full path to the current working directory.
Most current shells, such as
pwd as a built-in shell. It's behavior differs slightly from that of the standalone
/bin/pwd program. To see all locations containing
pwd, use the following command:
type -a pwd
Output pwd is a shell builtin pwd is /bin/pwd
The shell built-in takes precedence over the standalone executable, as shown in the output below, and it is utilized whenever you type
pwd. Type the complete path to the file /bin/pwd if you wish to use the standalone pwd binary.
How to Check your Current Working Directory
In your terminal, type
pwd to find out what directory you're in:
You will get an output like below:
PWD environment variable is printed by the
If you type, you'll get the same result:
Only two arguments are accepted by the
(--logical)- Symlinks are not resolved.
(—physical)- Show the physical directory without symbolic links.
If no option is supplied,
pwdbehaves as if the
-Loption is specified.
Let's construct a directory and a symlink linking to it to better understand how the
-P option works:
mkdir /tmp/directory ln -s /tmp/directory /tmp/symlink
If you go to the
/tmp/symlink directory and type
pwd in your terminal, you'll see:
Your current working directory is
/tmp/symlink, according to the output:
If you execute the same command with the
-P option, you'll get the following results:
The directory to which the symlink points will be printed by the command:
FAQs on pwd Command in Linux (Current Working Directory)
How do I use the
pwd command in Linux?
pwd command is straightforward. Open a terminal and type
pwd, then press Enter. The output will display the absolute path of the current working directory.
What is the difference between absolute and relative paths shown by the
pwd command always displays the absolute path, which represents the full path from the root directory to the current working directory. In contrast, relative paths are expressed relative to the current directory and do not start from the root.
pwd command show the symbolic link path instead of the actual path?
No, by default, the
pwd command shows the actual (canonical) path of the current working directory, not the path of a symbolic link pointing to it if one exists. To display the symbolic link path, you can use the
--physical option, like
pwd command display the username as part of the output?
pwd command only displays the absolute path of the current working directory, not the username or any other additional information. To display the username, you can use the
Is there any option or flag available for the
pwd command does not have any additional options or flags. It is a simple command that only displays the absolute path of the current working directory.
pwd command display paths with environment variables?
pwd command returns the actual directory path without expanding environment variables. If you want to view a path with expanded environment variables, such as
$USER, you can use
echo or other shell commands.
pwd command be run by any user?
Yes, any user can use the
pwd command to discover their current working directory. It does not require special permissions or elevated privileges.
The current working directory is the location from which you run terminal commands.
To see the current working directory, use the
If you have any queries, please leave a comment below and we’ll be happy to respond to them.