Main Content

Where am I and how did I get here?

Archive - Originally posted on "The Horse's Mouth" - 2007-07-05 18:19:44 - Graham Ellis

When you as "which directory am I in" with the pwd command, are you told the real directory you are in, or the one you cd'd into? You are normally tod the one you've cd'd to.

What's the difference? you may ask The difference is that you might want to find out where you really are on the file system (not with symbolic links) or how you got where you are (with symbolic links)

[trainee@daffodil webapps]$ pwd
/usr/local/tomcat/webapps
[trainee@daffodil webapps]$ pwd -P
/usr/local/jakarta-tomcat-5.5.9/webapps
[trainee@daffodil webapps]$ pwd -L
/usr/local/tomcat/webapps
[trainee@daffodil webapps]$


The -L option on pwd tells you the directory that you're in following links, and the -P option tells you where you really are. Note that these are the bash built in parameters; other shell's pwd commands may differ