PWD Command in Linux (Current Working Directory)

In this article, we will learn about how to determine your current working directory using the  pwd command. How to use pwd command in Linux.

What is the Current Working Directory

The current working directory is where the user currently working that directory is currently working directory. Each time you open the terminal, 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. If you want to change the working directory use the  cd command.

For example, to change the current working directory to  /dev  directory you would run the following command in the terminal:

$ cd /dev

PWD Command in Linux

If you have a customized  bash  or  zsh  prompt, the path to the current working directory may be shown in the shell prompt.

pwd Command

The pwdcommand stands for print working directory. It is one of the most basic and frequently used commands in Linux. When we use this command, it prints the complete path of the current working directory.

How to Find your Current Working Directory

To find out what directory you are currently in, type pwd command in your terminal:

$ pwd

PWD Command in Linux

The pwd command can accept four arguments:

  • -L (–logical) – Do not resolve symlinks.
  • -P (–physical) – Avoid all symlinks.
  • –help – Display this help and exit.
  • –version – Output version information and exit.

By default, pwd behaves as if the -L option is specified.

By default, id no option is used, pwd behaves as if the -L option is specified.

How the -P option works, we have to create a directory and symlink pointing to the directory:

$ mkdir /tmp/test$ ln -s /tmp/test /tmp/symlink

PWD Command in Linux

Now if we use the pwd command in the terminal to navigate /tmp/symlink directory

$ pwd

The output will show that your current working directory is /tmp/symlink:

PWD Command in Linux

If you run the same command using the -P option:

$ pwd -P

PWD Command in Linux

Conclusion

The current working directory is the directory where you run the commands in your terminal.

The pwd command is used to display the current working directory.

If you have any questions, feel free to leave a comment.

Related Posts:

Leave a Comment