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 –

pwd

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 –

val=$(pwd)

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

Conclusion

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 systemctl command in Linux

The systemctl command in Linux is responsible for controlling a widely adopted “systemd” init system and service manager. The init is the first process that starts when you power on

Commands 0 Comments

Using finger command in Linux

Finger command in Linux is used to display the details of a user. It includes information like login name, username, login time, idle time, home directory, etc. This command is

Commands 0 Comments

Using df command in Linux

Linux provides various tools to check disk space usage on file system. df command is one of them which stands for disk free. It displays the amount of disk space

0 Comments

No Comments Yet!

You can be first to comment this post!

Leave a Reply