Last week I ran a poll on Twitter to see what people considered with respect to the meaning of pwd in Unix and Linux systems. The results were varied, for perhaps good reason.
At the end of Oct 2020 I ran a brief poll on Twitter, on which 82 people voted. Heres that poll, and the results. Theyre quite mixed, which at first might seem surprising. But there are reasons for that, as well find out.
Print working directory
The most popular option was print working directory. At first sight it seems logical: print out the current working directory, i.e. where I am right now. Moreover, the description in various versions of the manual for pwd help to drive home that notion. Typically we see sentences like print name of current/working directory or print the current directory.
But there are lots of commands that print stuff, and are described in that way too. Take the id command. Heres what one man page says: print real and effective user and group IDs. Theres print again. But the command isnt pid, its id. When you think about it, many, many commands in Unix send information to STDOUT, i.e. to the terminal. Thats sort of the point of many of them.
This time arguably only superficially definitive, it would seem, the Wikipedia entry states, on the page for pwd: the pwd command (print working directory) writes the full pathname of the current working directory to the standard output. As if to underline the hopeful authority of this statement, there are five (!) footnotes that supposedly link to resources that back this up.
Unfortunately, the first footnote points to a Wayback Machine copy of the UNIX PROGRAMMERS MANUAL – Seventh Edition, Volume 1 – January, 1979, wherein there are actually zero references to pwd being short for print working directory:
I dont know about you, but this historic document carries more weight for me than other sources Ive come across, and it only serves here to undermine the credibility of the Wikipedia entry.
The rest of the footnote links seem dubious at best, except for the one pointing to the GNU Coreutils manual on pwd which has it as print working directory. But everything else Ive seen so far makes me think that this is a misunderstanding that has spread for obvious and innocent reasons. In addition, the one footnote in the Wikipedia page that is not used to back this claim up is a pointer to The Open Group Base Specifications Issue 7, 2018 editions information on pwd, which almost seems like its actually avoiding using the word print at all: return working directory name The pwd utility shall write to standard output an absolute pathname of the current working directory, which does not contain the filenames dot or dot-dot.. Very specific, very not-print.
So Im thinking that print working directory isnt what pwd stands for. In fact, print working directory may be common to some man pages, but on this macOS machine, with its BSD heritage, we have, instead: pwd return working directory name. Moreover, it goes on to say The pwd utility writes the absolute pathname of the current working directory to the standard output.
Pathname of working directory
So perhaps it really is pathname of working directory. That would, at least to me, make more sense. Not only does it eschew the redundancy of print, it also is more specific about the output – if Im in /home/dja/ for example, then invoking pwd will tell me that, i.e. where I am, including the whole path, and not just dja:
Process working directory
As for the other options, I do favour process working directory, mostly because it makes a lot of sense to me; every process in Unix has the concept of a current working directory, and thats exactly what Im asking for when Im in my shell process and enter pwd – theres a part in the video Unix terminals and shells that explains this very well.
Id love to be able to point to some old Unix sources that definitively explain the answer, but unfortunately that search has come up with very little – the pwd source in both the 5th and 6th Editions of Unix shed no light on this whatsoever.
Present working directory
What about present working directory? Well, that option seems to have legs, in the form of the Korn shell. While one source implies that the answer might well be pathname of current working directory, in that pwd just emits the value of the $PWD environment variable (and a variable called print working directory makes no sense at all) it would seem that in ksh-land, at least, present working directory is what pwd represents. Take, for example, the ksh man page which states PWD – The present working directory set by the cd command.
Theres a ton of discussion, both direct and indirect, on this very question. Take for example these two entries in the Unix & Linux Stack Exchange forum: Etymology of $PWD and What is $PWD? (vs current working directory). Of course, perhaps the definitive answer will never be found, as computing history is nothing if not varied and prone to forking.
Multics and print_wdir
Talking of history, we could go further back to pre-Unix roots, in the form of Multics, which indirectly gave rise to Unix (originally Unics). In the list of Multics Commands, we see, nestled amongst other similarly named commands, something that jumps out at us:
print_mail (pm)display mail in a mailbox
print_messages (pm)display interactive messages in a mailbox
print_motd (pmotd)display message of the day (source)
print_proc_auth (ppa)display process’s sensitivity level and compartments
print_request_types (prt)display list of I/O daemon request types
print_search_paths (psp)display search paths
print_search_rules (psr)display ready messages
print_wdir (pwd)display working directory
Theres pwd, and in fact, just like its sibling pmotd, for example, which is short for print_motd, its short for print_wdir. Now, given the context of the original poll being set to Unix and Linux, perhaps we must discount this information. But as someone who is fascinated with Unix history in general – how can I?
I guess there are few things to conclude. The history is rich and diverse, and maybe well never know for sure. Perhaps, in fact, the answer will depend on whom we ask. In the grand scheme of things, it doesnt really matter but to those who delight in minutiae, its a fun topic worth exploring.