PWD(1POSIX)
π PWD(1POSIX) β the POSIX Programmer's Manual, bestie edition π
okay so first things first, this page lives in the POSIX Programmer's Manual, and there's a lil heads-up before we even get to the good stuff π
π¨ PROLOG π¨
This manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (so like, go consult the corresponding Linux manual page for the deets on Linux behavior, fr), or honestly the interface might not even be implemented on Linux at all. π
β¨ NAME β¨
pwd β return working directory name. that's it. that's the whole job. iconic behavior honestly π
π¦ SYNOPSIS π¦
pwd [-L|-P]
πΈ DESCRIPTION πΈ
So the pwd utility shall write to standard output an absolute pathname of the current working directory. and ngl the key part: that pathname does not contain the filenames dot or dot-dot. no .. shenanigans, no . filler, we're keeping it clean β¨
π OPTIONS π
First off, the pwd utility shall conform to the Base Definitions volume of POSIX.1β2017, Section 12.2, Utility Syntax Guidelines. (yes bestie, there are rules, we follow them.)
The following options shall be supported by the implementation:
-Lβ If thePWDenvironment variable contains an absolute pathname of the current directory and that pathname doesn't contain any components that are dot or dot-dot,pwdshall write this pathname to standard output. EXCEPT (and this is the spicy caveat πΆοΈ): if thePWDenvironment variable is longer than{PATH_MAX}bytes including the terminating null, it is unspecified whetherpwdwrites this pathname to standard output or behaves as if the-Poption had been specified. Otherwise, the-Loption shall behave as the-Poption.-Pβ The pathname written to standard output shall not contain any components that refer to files of type symbolic link. If there are multiple pathnames that thepwdutility could write to standard output β one beginning with a single<slash>character and one or more beginning with two<slash>characters β then it shall write the pathname beginning with a single<slash>character. The pathname shall not contain any unnecessary<slash>characters after the leading one or two<slash>characters. periodt.
Now the tiebreaker tea β: if both -L and -P are specified, the last one shall apply. And if neither -L nor -P is specified, the pwd utility shall behave as if -L had been specified. (so -L is the default, she's the main character π
)
π OPERANDS π
None. nothing. zero. empty plate. π½οΈ
π STDIN π
Not used. not even a little bit.
π INPUT FILES π
None.
π ENVIRONMENT VARIABLES π
The following environment variables shall affect the execution of pwd:
LANGβ Provide a default value for the internationalization variables that are unset or null. (See the Base Definitions volume of POSIX.1β2017, Section 8.2, Internationalization Variables the precedence of internationalization variables used to determine the values of locale categories.) yes the sentence is long, i didn't write it, i just deliver it π«ΆLC_ALLβ If set to a non-empty string value, override the values of all the other internationalization variables. she's the boss of the group chat.LC_MESSAGESβ Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.NLSPATHβ Determine the location of message catalogs for the processing ofLC_MESSAGES.PWDβ An absolute pathname of the current working directory. β οΈ If an application sets or unsets the value ofPWD, the behavior ofpwdis unspecified. do not do this bestie, i'm begging.
π ASYNCHRONOUS EVENTS π
Default. she's chill.
β STDOUT β
The pwd utility output is an absolute pathname of the current working directory:
"%s\n", <directory pathname>
π©Ή STDERR π©Ή
The standard error shall be used only for diagnostic messages. she has one job and she does it.
π§ OUTPUT FILES π§
None.
π EXTENDED DESCRIPTION π
None.
π₯ EXIT STATUS π₯
The following exit values shall be returned:
0β Successful completion. we love a win π>0β An error occurred. π
π CONSEQUENCES OF ERRORS π
If an error is detected, output shall not be written to standard output, a diagnostic message shall be written to standard error, and the exit status is not zero.
π¨ okay this part matters a LOT: no partial output. zero. none. the whole thing fails clean, not messy.
The following sections are informative. (translation: the drama is over, this is just lore now π)
π APPLICATION USAGE π
If the pathname obtained from pwd is longer than {PATH_MAX} bytes, it could produce an error if passed to cd. So therefore, in order to return to that directory it may be necessary to break the pathname into sections shorter than {PATH_MAX} and call cd on each section in turn β the first section being an absolute pathname and subsequent sections being relative pathnames. yes bestie, chop it up like a friendship bracelet π
π¦ EXAMPLES π¦
None.
π RATIONALE π
Some implementations have historically provided pwd as a shell special built-in command. (lore π°οΈ)
In most utilities, if an error occurs, partial output may be written to standard output. This does not happen in historical implementations of pwd. Because pwd is frequently used in historical shell scripts without checking the exit status, it is important that the historical behavior is required here; therefore, the CONSEQUENCES OF ERRORS section specifically disallows any partial output being written to standard output. see?? told you it mattered.
An earlier version of this standard stated that the PWD environment variable was affected when the -P option was in effect. This was incorrect; conforming implementations do not do this. so if you heard that rumor, it was fake news, my bad for the old standard π
π FUTURE DIRECTIONS π
None.
π SEE ALSO π
cd- The Base Definitions volume of POSIX.1β2017, Chapter 8, Environment Variables, Section 12.2, Utility Syntax Guidelines
- The System Interfaces volume of POSIX.1β2017,
getcwd()
π COPYRIGHT π
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
and that's the whole page bestie!! π brought to you by IEEE/The Open Group, 2017 β the actual authors of this masterpiece, not me, i'm just the messenger with better vibes β¨ mwah, go run pwd and feel something π«Ά
π¦ where this page comes from
- debian bookworm: manpages-posix 2017a-2 Β· Other
- debian trixie: manpages-posix 2017a-2 Β· Other
- ubuntu jammy: manpages-posix 2017a-2 Β· Other
- ubuntu noble: manpages-posix 2017a-2 Β· Other
- ubuntu resolute: manpages-posix 2017a-2build1 Β· Other
- ubuntu stonking: manpages-posix 2017a-2.1 Β· Other
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms