pwd command is a command line utility for printing the current working directory. It will print the full system path of the current working directory to standard output. By default the
pwd command ignores symlinks, although the full physical path of a current directory can be shown with an option. The
pwd command is normally a shell builtin meaning it is part of the code that runs the shell rather than an external executable.
To print the current working directory run the
pwd command. The full path of the current working directory will be printed to standard output.
To avoid symlinks pass the
-P option. This will cause
pwd to show the physical location rather than a symlink. To demonstrate this the following example shows a folder that is symlinked to another location. Without the
-P option the symlink is ignored. In the following example the folder
zsh is a symlink.
ls -la | grep -E '.zsh$' lrwxrwxrwx 1 george users 25 Sep 15 2013 .zsh -> /home/george/dotfiles/zsh
pwd within the
zsh folder does not show the symlink.
cd .zsh pwd /home/george/.zsh
pwd with the
-P shows the physical location.
cd .zsh pwd -P /home/george/dotfiles/zsh
In most shells
pwd is a shell builtin. This means the command is present in the shell rather than calling an external program. This means that the code will run significantly faster than calling an external executable.
which pwd pwd: shell builtin command
Whilst most shells have
pwd as a shell builtin the command also exists on systems as an executable. On my own system the executable is located at
In most shells the
$PWD variable is available and is set each time a user or in script changes directory. As such this variable can be referenced to show the current working directory.
echo $PWD /home/george
$PWD is ubiquitous it is specific to the shell running the command so some prefer to reference the
pwd command and store it in a variable. This makes scripts more portable as they will call the system executable if the shell builtin or the
$PWD variable does not exist.
CWD=$(pwd) echo $CWD /home/george
$PWD variable is present is almost all shells it is possible it may not be there. If you are really paranoid use
CWD=$(pwd) but in most cases
$PWD will work.
Have an update or suggestion for this article? You can edit it here and send me a pull request.
Build your own Vim statusline
Statuslines in Vim are not hard to create. Making your own means one less dependency in your life.
Custom Vim Bindings in tmux 2.4
tmux 2.4 made a significant change to key bindings. Here is how to support custom keybindings for versions before and after tmux 2.4
Using template files in Vim
Vim templates or skeletons, allow you to specify a template to be used for new files with a certain extension.