Don't let symbolic links mislead you

does not work
Credit: flickr / David Goehring

Where am I?

Ever notice how, after following a symbolic link to a new directory, the pwd command shows you where you are in the file system according to the symbolic link rather than the actual file system location? This used to bother me until I discovered that there's an option for the pwd command that will cause the command to display your actual location and it's -P.

Symbolic links are handy, especially if you're wending your way into a directory that is deeply buried in the file system. I, for example, often have to work my way to a logs directory located in a place such as /home/oracle/jboss-4.2.2.GA/server/default/deploy/aveksa.ear/aveksa.war/log. That's a lot to type even with auto-completion. Instead, I'll make a symlink and see this:

$ cd
$ ln -s /home/oracle/jboss-4.2.2.GA/server/default/deploy/aveksa.ear/aveksa.war/log logdir
$ cd logdir
$ pwd

When I add the -P option, I get to see the actual location.

$ pwd -P

Obviously, in this case, I could look into my history and find my ln -s command but, in most cases, I set up the link months or years ago. Besides, I want my system to provide me with the answer I'm looking for and pwd -P does that for me.

By the way, this works for bash and ksh, but not csh.

This article is published as part of the IDG Contributor Network. Want to Join?

Computerworld's IT Salary Survey 2017 results
Shop Tech Products at Amazon