pwd

{{Short description|Shell command that reports the working directory}}

{{Other uses|PWD (disambiguation)}}

{{lowercase}}

{{Infobox software

| name = pwd

| logo =

| screenshot = Pwdkommando.png

| screenshot size =

| caption = The pwd command

| author = AT&T Bell Laboratories

| developer = Various open-source and commercial developers

| released = {{Start date and age|1974|6}}

| latest release version =

| latest release date =

| programming language = C

| operating system = Multics, Unix, Unix-like, V, Plan 9, Inferno, SpartaDOS X, PANOS, Windows CE, KolibriOS

| platform = Cross-platform

| genre = Command

| license = coreutils: GPLv3+
Plan 9: MIT License

| website =

}}

pwd (print working directory){{Cite web|url=https://www.unix.com/man-page/minix/1/pwd/|title=pwd(1) [minix man page]|website=www.unix.com}}{{Cite web|url=https://www.mankier.com/1/pwd|title=pwd - print name of current/working directory - man page|website=www.mankier.com}}{{Cite web|url=https://www.gnu.org/software/coreutils/manual/coreutils.html#pwd-invocation|title=GNU Coreutils|website=www.gnu.org}} is a shell command that reports the working directory path to standard output.{{cite book|url=http://cm.bell-labs.com/7thEdMan/v7vol1.pdf|title=Unix Time-Sharing System: Unix Programmer's Manual|edition=7th|volume=1|date=January 1979|publisher=Bell labs|page=142|archive-url=https://web.archive.org/web/20050520231659/http://cm.bell-labs.com/7thEdMan/v7vol1.pdf|archive-date=2005-05-20}}{{Cite web|title=pwd(1) [plan9 man page]|url=https://www.unix.com/man-page/plan9/1/pwd/|website=www.unix.com}}{{Cite web|url=https://pubs.opengroup.org/onlinepubs/9699919799/utilities/pwd.html|title=pwd|website=pubs.opengroup.org}}{{Cite web|url=https://www.unix.com/man-page/osf1/1/pwd/|title=pwd(1) [osf1 man page]|website=www.unix.com}}{{Cite web|url=https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/pwd.1.html|title=Apple OS X MAN page}}{{Cite web|url=https://man.openbsd.org/pwd.1|title=pwd(1) - OpenBSD manual pages|website=man.openbsd.org}}{{Cite web|url=https://www.unix.com/man-page/opensolaris/1/pwd/|title=pwd(1) [opensolaris man page]|website=www.unix.com}}

Although often associated with Unix, its predecessor Multics had a pwd command (which was a short name of the print_wdir command{{cite web |title=working_dir, wd, print_wdir, pwd (Multics help segment) |url=http://web.mit.edu/multics-history/source/Multics/doc/info_segments/working_dir.info |website=MIT |access-date=7 March 2020}}) from which the Unix command originated.{{cite web |last1=Van Vleck |first1=Tom |title=Unix and Multics |url=https://multicians.org/unix.html |website=Multicians.org |access-date=7 March 2020}} The command is part of the X/Open Portability Guide since issue 2 of 1987. It was inherited into the first version of POSIX.1 and the Single Unix Specification.{{man|cu|wc|SUS}} It appeared in Version 5 Unix.{{man|1|pwd|FreeBSD}} The version bundled in GNU Core Utilities was written by Jim Meyering.{{man|1|pwd|Linux}}

The command is available in other shells and operating systems including SpartaDOS X,{{Cite web|url=http://sdx.atari8.info/sdx_files/4.48/SDX448_User_Guide.pdf|title=SpartaDOS X 4.48 User Guide}} PANOS,{{Cite web|url=http://chrisacorns.computinghistory.org.uk/Panos.html#CL|title=Chris's Acorns: Panos|website=chrisacorns.computinghistory.org.uk}} and KolibriOS.{{Cite web|url=http://wiki.kolibrios.org/wiki/Shell|title=Shell - KolibriOS wiki|website=wiki.kolibrios.org}} PowerShell provides {{code|pwd}} as an alias for the cmdlet Get-Location. An equivalent command in COMMAND.COM and Command Prompt is the cd command with no arguments. On Windows CE 5.0, cmd.exe includes a pwd command.{{Cite web|url=https://docs.microsoft.com/en-us/previous-versions/windows/embedded/ms907227(v=msdn.10)|title=Command Processor Commands (Windows CE 5.0)|website=docs.microsoft.com}} The OpenVMS equivalent is show default.

The numerical computing environments MATLAB and GNU Octave include a pwd

function with similar functionality.{{Cite web|url=https://www.mathworks.com/help/matlab/ref/pwd.html|title=Identify current folder - MATLAB pwd|website=www.mathworks.com}}{{Cite web|url=https://octave.sourceforge.io/octave/function/pwd.html|title=Function Reference: pwd|website=octave.sourceforge.io}}

The command is implemented as a shell builtin in many Unix shells including sh, ash, bash, ksh, and zsh. It can be implemented with the POSIX getcwd() or getwd() functions.

Examples

The following examples are based on a typical Unix-based implementation.

With no arguments, the command writes the working directory path to the terminal:

$ cd /home/example

$ pwd

/home/example

Display the working directory without any symbolic link info. If at a directory /home/symlinked that is a symlink to /home/realdir:

$ cd /home/symlinked

$ pwd -P

/home/realdir

Display the working directory with symbolic link info. Note: POSIX requires that the default behavior be as if the -L switch were provided.

$ pwd -L

/home/symlinked

Shell variables

POSIX shells set the following environment variables while using the {{code|cd}} command:{{Cite web|url=https://pubs.opengroup.org/onlinepubs/9699919799/utilities/cd.html|title=cd|website=pubs.opengroup.org}}

; OLDPWD : The previous working directory

; PWD : The current working directory

See also

References

{{Reflist}}

Further reading

  • {{cite book

| author-last = McElhearn

| author-first = Kirk

| title = The Mac OS X Command Line: Unix Under the Hood

| date = 2006

| publisher = John Wiley & Sons

| isbn = 978-0470113851}}