PWD(1P)
π PWD(1P) β POSIX Programmer's Manual π
okay bestie, welcome to pwd, from the POSIX Programmer's Manual (that's the 1P section, iykyk). this is the page for the little command that tells you where you are, which sounds boring until you realize you'd be absolutely lost without it. literally.
πΈ PROLOG πΈ
okay so real talk before we start: this manual page is part of the POSIX Programmer's Manual. the Linux implementation of this interface may differ β so if you're on Linux, go peek at the corresponding Linux manual page for the Linux behavior, okay? or it might not be implemented on Linux at all. no cap, that's just how it is. π
β¨ NAME β¨
pwd β return working directory name π
π¦ SYNOPSIS π¦
pwd [-L|-P]
that's it. that's the whole vibe. π
π DESCRIPTION π
so here's the tea: the pwd utility shall write to standard output an absolute pathname of the current working directory, and that pathname does not contain the filenames dot or dot-dot. none of that .. nonsense. we're giving clean, absolute, main-character pathname energy. β¨
π OPTIONS π
first things first, the pwd utility shall conform to the Base Definitions volume of POSIX.1β2017, Section 12.2, Utility Syntax Guidelines. iconic behavior, we love to see it.
the following options shall be supported by the implementation:
-Lβ if thePWDenvironment variable contains an absolute pathname of the current directory and the pathname does not contain any components that are dot or dot-dot,pwdshall write this pathname to standard output. BUT β and this is the plot twist β except that 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. and the pathname shall not contain any unnecessary<slash>characters after the leading one or two<slash>characters. so like, no extra slashes, we're not messy. β¨
and now the important bit: if both -L and -P are specified, the last one shall apply. last one wins, periodt. π
and if neither -L nor -P is specified, the pwd utility shall behave as if -L had been specified. so -L is the default, bestie. remember that.
π§ OPERANDS π§
none. she takes no operands. she's independent. she doesn't need your arguments. π
π STDIN π
not used. she's not reading your vibes from stdin, okay?
π INPUT FILES π
none. zero. nada.
π 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 for the precedence of internationalization variables used to determine the values of locale categories.)LC_ALLβ if set to a non-empty string value, override the values of all the other internationalization variables. she's the boss. π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. so likeβ¦ don't do that? that's the warning, bestie.
π₯ ASYNCHRONOUS EVENTS π₯
default. nothing special happening here, we're chill.
β STDOUT β
the pwd utility output is an absolute pathname of the current working directory:
"%s\n", <directory pathname>
yes the newline is included. we're tidy. π
πΈ STDERR πΈ
the standard error shall be used only for diagnostic messages. that's it. no small talk.
π¦ OUTPUT FILES π¦
none. she's not writing files, she's writing to stdout. different thing entirely.
π EXTENDED DESCRIPTION π
none. there is no extended description. moving on, bestie. π
β¨ EXIT STATUS β¨
the following exit values shall be returned:
0β successful completion. slay. π>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 so this part is important: no partial output. like, none. she either gives you the whole pathname or she gives you nothing and yells at stderr instead. that's the rule.
the following sections are informative. π
π APPLICATION USAGE π
if the pathname obtained from pwd is longer than {PATH_MAX} bytes, it could produce an error if passed to cd. π 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). yeah. chunk it. it's giving workaround but it works. π
π EXAMPLES π
none. no examples here, sorry bestie. the synopsis is honestly the whole show.
π RATIONALE π
some implementations have historically provided pwd as a shell special built-in command. fun fact of the day. π
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. so yeah, that rule up there? that's why. π«‘
and one more: 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, bestie, it's fake news. PWD is not getting touched by -P.
π§ FUTURE DIRECTIONS π§
none. the future is bright and unchanged. π
π 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 .
aaaand that's the whole page, bestie!! πβ¨ this was IEEE/The Open Group, published in 2017, and the page is PWD(1P) β so go forth and pwd responsibly. ilysm, drink water, check your exit statuses. ππ¦πΈπ
π¦ where this page comes from
- alpine 3.22: man-pages-posix 2017a-r0 Β· custom
- alpine 3.23: man-pages-posix 2017a-r0 Β· custom
- alpine 3.24: man-pages-posix 2017a-r0 Β· custom
- arch rolling: man-pages 6.19-1
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages-posix 2017a
- opensuse-leap 16.0: man-pages-posix 2017a-160000.4.1 Β· SUSE-IEEE
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms