How to use the Linux pwd command

The Linux command pwd inserts the entire path of your current working directory into the standard output. The command is essential for maintaining accurate directory tracking in Linux and can be customised various ways.

What is the Linux pwd command?

pwd stands for ‘Print Working Directory’ in Linux. Along with the Linux cd command, it’s one of the most frequently used commands for everyday tasks. The main task of pwd is to insert the complete pathname of the current directory into the output. The individual subdirectories are separated by dashes. The pwd command is available as a built-in command and as a stand-alone program. This is included in the standard installation of all common Linux distributions like Debian or Ubuntu.

How does Linux pwd work?

Using the pwd command you get the full path of your current directory in the output. This is advantageous if you frequently switch between directories or work with numerous subdirectories. With Linux pwd you retain an overview of all your paths and can save or access files in a targeted manner, even in extensive projects.

What is the syntax of the pwd command?

The syntax of Linux pwd is simple and always looks like this:

$ pwd [Options]
bash

When you execute the pwd command without any options, it will display the full pathname of your current working directory as output. Thanks to different options you can customise this output.

What are the Linux pwd command options?

The pwd command has two important options which are mutually exclusive:

  • -L: Even if the ‘physical’ option is set in the shell, the pwd command will not resolve symbolic links and will display the symbolic link itself if present.
  • -P: This option resolves a symbolic link.

The program /bin/pwd, on the other hand, recognises only the ‘–help’ option. By using it, you can retrieve additional information about the pwd command, including its usage and available options.

Examples for the pwd command

When you execute the pwd command, it will always display the path of your current working directory as the output. To obtain this result, simply enter the command exactly as shown in the syntax section above. The output will resemble the following:

/home/subfolder
bash

If you use the program, run Linux pwd as follows:

/bin/pwd
bash

The output is as above:

/home/subfolder
bash

If you now add the option ‘-L’, the command looks like this:

/bin/pwd -L
bash

The appropriate output would look like this:

/home/subfolder/dir_simlink
bash