The pwd command

The pwd Bash builtin prints the current working directory for the script to the standard output:

$ pwd
/home/bashuser
This information is also available in the PWD environment variable, which can be more flexible to use in scripts.

The working directory for the shell refers to the directory from which all relative paths are based, even if they have multiple levels of directories in them:

$ pwd
/home/bashuser/docs
$ ls important/doc1.txt
important/doc1.txt
$ ls doc2.txt
doc2.txt
$ ls nonexistent
ls: cannot access 'nonexistent': No such file or directory

Any path that starts with a forward slash  a leading slash  is instead an absolute path, and resolves independently of the current directory:

$ ls /home/bashuser/important/doc1.txt ...

Get Bash Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.