pwd
This subchapter looks at pwd, a UNIX (and Linux) command.
pwd stands for Print the Working Directory. It provides the full path for the current working directory. and is normally run without any options.
pwd is a builtin command in bash. There is also an external utility with the same name and functionality.
working directory
The working directory is whatever directory you happen to be working in. The working directory is always the same as the home directory when you start a shell session, but you can change your working directory at any time (and typically do change it). Commands normally are applied to the current working directory.
The working directory may also be called the current directory, current working directory, or present working directory.
using pwd
Type pwd from the command line, followed by ENTER or RETURN, and you will see the current working directory.
$ pwd
/Users/admin
$
Theres not much else to tell you about this command, but this is an important one because you will continually have the need to know where you are.
moving around
We will go into more detail about these commands later, but for now you need to know how to move around in your file system.
The ls command is used to list the contents of the current directory.
Go ahead and type ls followed by ENTER or RETURN and you will see a list of the files and directories in your current working directory (which should still also be your home directory).
The cd command is used to change directories.
Go ahead and type cd directory-name followed by ENTER or RETURN and you will move to the new directory. You can confirm this by then typing pwd followed by ENTER or RETURN. You will see that you have successfully changed working directories.
$ pwd
/Users/admin
$ ls
Desktop Movies Send Registration
Documents Music Sites
Downloads Pictures
Library Public
$ cd Desktop
$ pwd
/Users/admin/Desktop
$
As you move around the directory tree, it is common to forget exactly where you are, especially if you do some other tasks (such as file editing). pwd provides an easy way to determine where you are and insure that your next actions are happening in the correct directory.
Use cd command all by itself to return to your home directory.
$ cd
$ pwd
/Users/admin
$
advanced topic
The remainder of this subchapter covers an advanced topic. I am placing this here so that you will be easily able to find them when you are ready for this information.
Eventually you will make use of symlinks and symlinked directories. There will be times when you need toknow the actual physical path to the current working directory, not just the logical symlinked path.
options
pwd is almost always used without options and never uses any arguments (such as file names). Anything other than legal options typed after pwd are ignored. Some shells ignore anything other than the legal options typed after pwd without reporting any errors, while most shells report errors for illegal options. All shells seem to ignore all arguments without reporting any errors.
The two main options for pwd are -L and -P.
The -L option displays the logical current working directory. This is the default if no options are listed.
$ cd /symlink
$ pwd -L
/symlink
$
The -P option displays the physical current working directory, with all symbolic links resolved.
$ pwd -P
/Users/admin
$
You can use the results of the pwd -P switch to cd to the physical directory.
$ cd /Users/admin
$
You can also use the -P switch directly on the cd command to change to the physical directory.
$ cd -P /symlink
$ pwd
/Users/admin
$
You can use the help command to get information about pwd.
$ help pwd
Some early Linux shells allow the --help command to get information about pwd.
$ pwd --help
Some early Linux shells allow the --version option gives the version number for your copy of pwd.
$ pwd --version
other
On November 8, 2010, Ramesh Natarajan named this the number 13 most frequently used UNIX/Linux command at this web page 50 Most Frequently Used UNIX / Linux Commands (With Examples).
In June 2009, Ken Milberg named this command as one of the Top 50 universal UNIX commands at this web page Top 50 Universal INIX commands. Note that this web page requires agreeing to be spammed before you can read it.
comments, suggestions, corrections, criticisms
free music player coding example
Coding example: I am making heavily documented and explained open source code for a method to play music for free almost any song, no subscription fees, no download costs, no advertisements, all completely legal. This is done by building a front-end to YouTube (which checks the copyright permissions for you).
View music player in action: www.musicinpublic.com/.
Create your own copy from the original source code/ (presented for learning programming).
Because I no longer have the computer and software to make PDFs, the book is available as an HTML file, which you can convert into a PDF.
Names and logos of various OSs are trademarks of their respective owners.