Using pwd command in Linux

Using pwd command in Linux


The pwd is a command in Linux which displays the current working directory of a user. So you might think what is the current working directory? while working in a Linux terminal you navigate among different directories in your system. Directories in Linux are organized in a tree structure under the / so if you use pwd command it displays the full path where you are currently in the directory tree.

The pwd command

Pwd stands for the print working directory when you use this command in your terminal it prints the working directory of a user. It is a built-in Linux command that stores the working path in the $PWD environment variable.

Syntax of the command-

pwd [option]

How to display the current working directory in Linux

While moving from one directory to another you can check where are you at any point of time using the pwd command. You can use the pwd command in one of the given forms –

We generally use pwd command without any argument as it is given below –


Or using option -L will print the working directory even if contains symbolic links

pwd -L

Using pwd with option -P will print the actual path without symlinks –

pwd -P

How to store the output of pwd command in a variable

Now let’s say you want to store the output of the pwd command in a variable called val then use the following command in your terminal –


You can print the value inside val variable by using –

echo "The current working directory is: $val"

How to display the previous working directory

If you want to see the previous working directory then you can use the following command in your terminal –

echo "$OLDPWD"

You can see the manual page of pwd by using the following command in your terminal –

man pwd


Now you know how to check the current or previous working directory in your terminal. You can share your thought or ask queries in the comments below.

Previous What are symlinks and how to create them in Linux?
Next Remove my account

About author

You might also like

Commands 0 Comments

Using whois command in Linux

This post was last updated on January 16th, 2021 at 12:13 pmWhois command in Linux searches in a WHOIS database. This database stores the registered users of an internet resource

Commands 0 Comments

Using cd command in Linux

While working in a Linux terminal you often need to switch from one directory to another. The cd is a command used to change the directory in Linux. This command

Commands 0 Comments

How to rename files & directories in Linux?

There are various ways in which you can rename the files or directories on a Linux system. If you are using a system with a graphical user interface then you


No Comments Yet!

You can be first to comment this post!

Leave a Reply