A command like pwd
inherits the current directory of the process
that started it (usually, a shell).
It could be started from anywhere.
How does pwd
find out where it is in the filesystem?
for a picture of the current directory /usr/joe
and its parent
The current directory doesn't contain its own name, so that doesn't help
But it has an entry named
The current directory has i-number 234.
asks UNIX to open the parent directory file,
the directory one level up,
through the relative pathname (
looks at the
Same steps: look in the parent, i-number 12. What's its name? Hmmm. The i-number of its parent, 12, is the same as its own-and there's only one directory on the filesystem like this: the root directory. So, pwd adds a slash to the start of the pathname and it's done: /usr/joe .
That's really missing one or two parts: Filesystems can be mounted on other filesystems, or can be mounted across the network from other hosts. So, at each step, pwd also needs to check the device that the current directory is mounted on. If you're curious, see the stat (2) manual page or check a UNIX internals book. Also see the last few paragraphs of article 18.4 for more about the links between directories.
Amri kama pwd urithi directory ya sasa ya mchakato kwamba ilianza yake (kwa kawaida, shell). Inaweza kuanzishwa kutoka mahali popote. Jinsi gani pwd kupata ambapo ni katika mfumo wa faili? "Kama ilivyoelezwa hapo juu, ""forusr"" ni jina la directory ya sasa, lakini kwa sababu ya kuwa na jina la directory ya sasa, ""forusr"" ni jina la directory ya sasa, kwa hivyo ""forusr"" ni jina la directory ya sasa, na ""forusr"" ni jina la directory ya sasa, na ""forusr"" ni jina la directory ya sasa." Jina lake ni nani? Hm. Hm. Nambari ya i ya mzazi ni 12, na kuna orodha moja tu kwenye mfumo wa faili kama hii: orodha ya mzizi. "PwD inaongeza slash kwa mwanzo wa njia ya jina na ""usr"" na ""joe""." Hii ni moja ya mambo muhimu sana katika mfumo wa faili, kama vile kuweza kuunganisha faili kwenye mfumo mwingine wa faili au kuunganisha faili kwenye mtandao kutoka kwa mwenyeji mwingine. Hivyo, katika kila hatua, pwd pia anahitaji kuangalia kifaa kwamba directory sasa ni imewekwa juu. Kama wewe ni curious, angalia stat (2) ukurasa wa mwongozo au kuangalia UNIX book internals. Pia angalia mafungu machache ya mwisho ya kifungu 18.4 kwa zaidi kuhusu viungo kati ya directory.