Jump to content

pwd

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by 97.77.188.52 (talk) at 20:39, 28 June 2020. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.


In Unix-like and some other operating systems, the pwd command (print working directory)[1][2] writes the full pathname of the current working directory to the standard output.[3][4][5][6][7]

Implementations

Multics had a pwd command (which was a short name of the print_wdir command)[8] from which the Unix pwd command originated.[9] The command is a shell builtin in most Unix shells such as Bourne shell, ash, bash, ksh, and zsh. It can be implemented easily with the POSIX C functions getcwd() or getwd().

It is also available in the operating systems SpartaDOS X,[10] PANOS,[11] and KolibriOS.[12] The equivalent on DOS (COMMAND.COM) and Microsoft Windows (cmd.exe) is the cd command with no arguments. Windows PowerShell provides the equivalent Get-Location cmdlet with the standard aliases gl and pwd. On Windows CE 5.0, the cmd.exe Command Processor Shell includes the pwd command.[13]

pwd as found on Unix systems 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.[14] It appeared in Version 5 Unix.[15] The version of pwd bundled in GNU coreutils was written by Jim Meyering.[16]

The numerical computing environments MATLAB and GNU Octave include a pwd function with similar functionality.[17][18] The OpenVMS equivalent is show default.

*nix examples

Command Explanation
pwd Display the current working directory. Example: /home/foobar
pwd -P Display the current working directory physical path - without symbolic link name, if any. Example: If standing in a dir /home/symlinked, that is a symlink to /home/realdir, this would show /home/realdir
pwd -L Display the current working directory logical path - with symbolic link name, if any. Example: If standing in a dir /home/symlinked, that is a symlink to /home/realdir, this would show /home/symlinked

Note: POSIX requires that the default behavior be as if the -L switch were provided.

Working directory shell variables

POSIX shells set the following environment variables while using the cd command:[19]

OLDPWD
The previous working directory (as set by the cd command).
PWD
The current working directory (as set by the cd command).

See also

References

  1. ^ Unix Time-Sharing System: Unix Programmer's Manual (PDF). Vol. 1 (7th ed.). Bell labs. January 1979. p. 142. Archived from the original (PDF) on 2005-05-20.
  2. ^ Minix MAN page
  3. ^ POSIX Standard (IEEE Std 1003.1) pwd page
  4. ^ DEC OSF/1 MAN page
  5. ^ Apple OS X MAN page
  6. ^ OpenBSD MAN page
  7. ^ OpenSolaris MAN page
  8. ^ "working_dir, wd, print_wdir, pwd (Multics help segment)". MIT. Retrieved 7 March 2020.
  9. ^ Van Vleck, Tom. "Unix and Multics". Multicians.org. Retrieved 7 March 2020.
  10. ^ SpartaDOS X 4.48 User Guide
  11. ^ http://chrisacorns.computinghistory.org.uk/Panos.html#CL
  12. ^ http://wiki.kolibrios.org/wiki/Shell
  13. ^ "Command Processor Commands (Windows CE 5.0)". docs.microsoft.com.
  14. ^ wc – Shell and Utilities Reference, The Single UNIX Specification, Version 4 from The Open Group
  15. ^ pwd(1) – FreeBSD General Commands Manual
  16. ^ pwd(1) – Linux User Manual – User Commands
  17. ^ https://www.mathworks.com/help/matlab/ref/pwd.html
  18. ^ https://octave.sourceforge.io/octave/function/pwd.html
  19. ^ POSIX Standard (IEEE Std 1003.1) cd page

Further reading