In any distribution, which is based on Linux, there is a huge amount of simple console utilities that perform a limited, but very useful set of actions. The list of such tools includes PWD (Present Working Directory). If you transfer the decoding of the abbreviation, it becomes clear that this command is designed to display the current active directory in the console, where the work is now. As part of today's article, we want to tell everything about the use of this tool, bringing visual examples.
Apply the PWD command in Linux
Let's start with the applications of the PWD command. Of course, first of all, the task of determining the path of the current catalog is coming to the mind, which in the future can be used to save various files or apply under other circumstances. Additionally, the value of this utility is assigned to variables or add this command to scripts, as they also mention further. At first, imagine the simplest example of using PWD, and then we will already affect additional options.PWD activation in console
The PWD syntax is extremely simple because it turns on this utility only two options. We will look at them later, and now let's analyze the standard situation in a small step-by-step example.
- Run the "Terminal" convenient for you, for example, through the icon in the application menu.
- Next, go to the necessary path or perform absolutely any actions. We specifically chose the location to further show how PWD will display it in a new line. We use the CD command for this.
- Now it's enough just to register PWD. For this, it is not even necessary to use sudo, since this command does not depend on the superuser's rights.
- On the screen in the new line immediately appears the full path to the current location.
As you can see, the location is determined via PWD literally in a few seconds, while there are no restrictions on the current active directory: it may even be a network folder.
Use options
As already mentioned above, there are only two available options in PWD that you can apply when executing the command.
- If you enter the PWD -L, the new line will show the result without converting symbolic links.
- PWD -P, on the contrary, all the symbolic links converts to the source names of the directories where they were indicated.
- Enter pwd --help, to display the official documentation. In it you can learn how to describe the options the developers themselves.
Earlier we did not specifically explain what symbolic links as the subject in a separate article on our site. It describes the ln command, which is directly related to hard and symbolic links, therefore it is advisable to study it to find out more information on this topic.
Details: ln command on Linux
Additional actions to PWD
PWD command can be associated with the creation or viewing of scripts and it can be written in the variable. All this relates to additional activities that we, too, will address within the material.
- If your location refers to a script, use the environment variable through the echo $ PWD, to find out the current path.
- If necessary, create a variable with a record of your current location, type CWD = $ (pwd), where CWD - variable name. The same command is used when creating a custom script, its appearance can be represented in the embodiment DIR = `pwd`.
- Now you can call via variable echo $ CWD, activating the command by pressing Enter.
- The result will be the same as in the case under consideration using standard tools.
That's all we wanted to talk about the standard utility Linux operating system under the name of PWD. As you can see, it is narrowly focused team that allows to determine only one option, but it finds its application in a variety of situations.