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.
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.
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
- 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
- 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
- Lastly we will check what happens when we run just
pwd
. From the output, it's pretty much clear thatpwd
takes-L
as the default flag if no options are provided.
$ pwd
/Users/umesh/h
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)
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