Current Working Directory (PWD Command)

Published on March 5, 2023 · Updated on March 24, 2023
Current Working Directory (PWD Command)

As a Linux user, you may find yourself needing to know your current working directory at times. The pwd command can help you find out where you are in the file system. It is a simple but useful tool that can be used to navigate the file system, set the working directory for scripts and programs, and create relative paths.

How to find the current working directory in Linux

To find the current working directory in Linux you just need to type the pwd command into the command line. “PWD” stands for “print working directory”. As the name suggests, it is a simple command that prints the current working directory to the terminal.

To use the pwd command, simply open a terminal window and type:

pwd

This will print the current working directory to the terminal. For example, if you are in the /home/user/Documents directory, the output will be:

/home/user/Documents

PWD Command Tips

In addition to simply printing out the current working directory, the pwd command can also be used in conjunction with other commands. For example, you can use the pwd command to set the working directory for a script or program.

Let’s say you have a script located in /home/user/scripts that you want to run, but it requires you to be in the same directory as the script. You can use the pwd command to set the working directory for the script like this:

cd $(pwd)/scripts
./myscript.sh

This will change the working directory to /home/user/scripts and then run the script myscript.sh.

Another useful feature of the pwd command is that it can be used to create relative paths. For example, let’s say you are in the directory /home/user/Documents and you want to navigate to the directory /home/user/Pictures. Instead of typing out the full path, you can use the pwd command like this:

cd $(pwd)/../Pictures

This will change the working directory to /home/user/Pictures.

Conclusion

In conclusion, the pwd command is a simple but powerful tool that can help you navigate the Linux file system with ease. By using this command, you can quickly and easily find out where you are in the file system, set the working directory for scripts and programs, and create relative paths.

Load Comments