PWD command in Linux

Anonim

PWD command in Linux

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.

  1. Run the "Terminal" convenient for you, for example, through the icon in the application menu.
  2. Starting the terminal to use the PWD utility in Linux

  3. 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.
  4. Go to location to use the PWD utility in Linux

  5. 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.
  6. Enter the command to use the PWD utility in Linux

  7. On the screen in the new line immediately appears the full path to the current location.
  8. The result of using the PWD utility in Linux in the new terminal string

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.

  1. If you enter the PWD -L, the new line will show the result without converting symbolic links.
  2. Application Output options Symbolic links when using PWD in Linux

  3. PWD -P, on the contrary, all the symbolic links converts to the source names of the directories where they were indicated.
  4. Application of symbolic symbolic conversion option when using the PWD command in Linux

  5. Enter pwd --help, to display the official documentation. In it you can learn how to describe the options the developers themselves.
  6. Conclusion official documentation PWD command in Linux

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.

  1. If your location refers to a script, use the environment variable through the echo $ PWD, to find out the current path.
  2. Using PWD variable in Linux when working with scripts

  3. 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`.
  4. Creating a variable retaining PWD command output on Linux

  5. Now you can call via variable echo $ CWD, activating the command by pressing Enter.
  6. The use of variable data output of PWD in Linux

  7. The result will be the same as in the case under consideration using standard tools.
  8. Familiarization with the result of the variable PWD entry on Linux

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.

Read more