DEV Community

Cover image for Linux Commands: pwd
Umesh Yadav
Umesh Yadav

Posted on • Edited on • Originally published at umesh.dev

Linux Commands: pwd

pwd is one of the most helpful commands for linux newbie. Whenever you are lost just type it in your terminal and you will find where are you exactly. Let me show you how you can do it.

Screenshot 2020-10-08 at 11.39.27 PM.png

You can see it tells me my current working directory. Usually, there are two ways you can invoke this command. One way you already saw in the above example. The other way is through /bin/pwd they are almost the same. But pwd is your shell in-built command while /bin/pwd is calling the binary version of that. You can always verify which pwd is getting invoked by using which or type command shown below.

Screenshot 2020-10-08 at 11.47.27 PM.png

pwd has two flags one is -L and -P.

  • -L: Display the logical current working directory.
  • -P: Display the physical current working directory (all symbolic links resolved).

Let's see them in action and understand what exactly one does.

  • We will create a symbolic link of folder /var/log as h in your home directory and move to it.
$ ln -s /var/log h
$ cd h
Enter fullscreen mode Exit fullscreen mode
  • We will print the working directory using the logical flag pwd -L. It will print the exact working directory from the environment even if it contains symlinks.
$ pwd -L
/Users/umesh/h
Enter fullscreen mode Exit fullscreen mode
  • After that we will print the working directory using physical flag pwd -P. It will print actual physical current working directory by resolving all symbolic links.
$ pwd -P
/private/var/log
Enter fullscreen mode Exit fullscreen mode
  • Lastly we will check what happens when we run just pwd. From the output, it's pretty much clear that pwd takes -L as the default flag if no options are provided.
$ pwd
/Users/umesh/h
Enter fullscreen mode Exit fullscreen mode

Screenshot 2020-10-08 at 11.56.48 PM.png

Conclusion

I will be writing more on these simple and yet useful commands in my coming blog. Linux commands look simple and probably you remember it but if you know a bit in-depth about them they can come in handy.

If you liked this blog please feel free to share with others, if you are sharing it on twitter please tag @imumesh18 . If you are interested in more of these please subscribe to my newsletter.

Top comments (1)

Collapse
 
aurelien_57 profile image
richerioux

Bonjour
Je suis en test pour entrer dans une école en développeur intelligence artificielle ! Les tests son à faire soit en autonomie où avec l'aide d'autres personnes.
J'ai besoin d'aide dans le test je suis à un cours pwd et la et

Quel est le chemin du répertoire de travail actuel juste après votre connexion ?
J'ai fait plein de recherche, j'ai utilisé tout les commandes en réponse à chaque fois mal répondus !! Sachant que je me connecte avec putty wind pour linux .

merci