Showing Where You Are

Problem

You are not sure what directory you are in, and the default prompt is not helpful.

Solution

Use the pwd built-in command, or set a more useful prompt (as in Customizing Your Prompt). For example:

bash-2.03$ pwd
/tmp

bash-2.03$ export PS1='[\u@\h \w]$ '
[jp@solaris8 /tmp]$

Discussion

pwd stands for print working directory and takes two options. -L displays your logical path and is the default. -P displays your physical location, which may differ from your logical path if you have followed a symbolic link.The cd command also provides the -P and -L switches.

bash-2.03$ pwd
/tmp/dir2

bash-2.03$ pwd -L
/tmp/dir2

bash-2.03$ pwd -P
/tmp/dir1

Get bash Cookbook 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.