In this tutorial, we'll show you how to make the pwd command in Linux used to determine the current working directory.
What is the current working directory
The current working directory is the user's current working directory being located. Every time when interacting with the command prompt, you are working in the directory.
By default, when you log on Linux systems, 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 custom bash or zsh prompt, the current path of the working directory may appear in the shell prompt.
user@host:/tmp#
pwd command
Pwd command is an abbreviation for print working directory. Linux is one of the most basic and most frequently used commands. When executed, this command will print the full path of the current working directory.
pwd is built into most modern shell, such as bash and zsh. It behaves independent / bin / pwd executable files is slightly different. You can use it to display all type -a position pwd included.
type -a pwd
pwd is a shell builtin pwd is /bin/pwd
As it can be seen from the following output, the shell built priority to an independent executable file, whenever the input pwd will preferentially use the built. If you want to use a separate pwd command, you need to use the full path to the binary file / bin / pwd
How to find your current working directory
To find out your current directory, enter pwd at your terminal:
pwd
This command displays the current working directory:
/home/linuxidc
The role of the command is printing environment variable PWD. If you type the following, you will get the same output:
echo $PWD
/home/linuxidc
The pwd command only accepts two parameters:
- -L (--logical) - displays the value of the variable $ PWD. By default, pwd performance -L option is specified.
- -P (--physical) - shows the physical directory, without any symbolic links
In order to better illustrate the working principle of the -P option, we will create a directory and point to [symbolic link to that directory:
mkdir /tmp/directory ln -s /tmp/directory /tmp/symlink
Now, if you navigate to / tmp / symlink directory and enter pwd:
cd /tmp/symlink
pwd
Output will display your current working directory / tmp / symlink.
/tmp/symlink
If you use the same command to run the following -P options:
pwd -P
Your current working directory is a symbolic link to the directory / tmp / directory.
/tmp/directory
in conclusion
By now, you should have a good understanding of what the current working directory is and how to use pwd command to find the current working directory.