DEV Community

dpm_bush
dpm_bush

Posted on Originally published at sshflow.com

pwd in Linux: Know Which Directory Your Shell Is In

A command can behave differently depending on the directory your shell is in. Before you edit a file, run a script, or use a relative path, check your location with pwd.

What pwd tells you

pwd means “print working directory.” Run it without arguments:

pwd
Enter fullscreen mode Exit fullscreen mode

You might see:

/home/alex/projects
Enter fullscreen mode Exit fullscreen mode

That is the current working directory for this shell session. It is usually shown as an absolute path, starting at the filesystem root (/). A relative path such as src/app.js is interpreted from this location.

Your current directory is not necessarily your home directory. You can navigate elsewhere and return to your home directory later. To change locations, use cd and its directory-navigation shortcuts; pwd only reports where you are.

Each terminal or shell session tracks its own location. If one terminal is in /home/alex/projects and another is in /tmp, their pwd output will differ.

Use it before working with relative paths

Suppose you expect a configuration file to be in your project, but you are not sure where the terminal started. Check first:

pwd
Enter fullscreen mode Exit fullscreen mode

Then inspect the current directory's contents:

ls
Enter fullscreen mode Exit fullscreen mode

These commands answer different questions: pwd shows your location, while ls shows what is there. If you need to inspect hidden files or change how entries are displayed, see these practical ls examples.

This check is especially useful before commands that use relative paths. For example, ./script.sh refers to a script in the current directory—not necessarily the directory where the script is stored. If a command reports “No such file or directory,” an unexpected working directory is one possible cause.

Logical and physical paths

A directory may be reachable through a symbolic link. In that case, there can be two useful ways to describe your location:

  • The logical path preserves the path you used, including a symbolic link.
  • The physical path resolves symbolic links to the underlying directory.

On shells and implementations that support these options, request the logical or physical path explicitly:

pwd -L
pwd -P
Enter fullscreen mode Exit fullscreen mode

For example, if /var/www points to /srv/site, the logical path may be /var/www, while the physical path may be /srv/site. The actual output depends on your filesystem and shell.

Plain pwd commonly reports a logical path in popular shells, but defaults can vary between shell built-ins and standalone utilities. If the distinction matters—for example, when diagnosing a path issue—use -L or -P and check the behavior of the shell you are running.

pwd on Windows depends on the shell

The command name does not mean exactly the same thing in every Windows environment:

  • In PowerShell, pwd is an alias for Get-Location.
  • In Command Prompt, use cd or echo %CD% to display the current directory.
  • In WSL or Git Bash, you are using a Unix-like shell where pwd is available.

So if pwd works in one Windows terminal but not another, check which shell that terminal is running.

A useful habit

When a command seems to be looking in the wrong place, verify the shell's current directory before changing files or retrying with different paths:

pwd
ls
Enter fullscreen mode Exit fullscreen mode

The first command tells you where relative paths start; the second helps confirm what is in that location. That small check can prevent mistakes caused by assuming the terminal is somewhere it isn't.

I originally published a more detailed version of this guide on the SSHFlow blog.

I'm also building SSHFlow — an SSH client where every server gets its own workspace for terminals, SFTP, code, and databases.

Top comments (0)