When I try to find the current working directory at a linux command prompt (using "pwd"), it will show the directory with symbolic links included. For example, if I make a symbolic link and use it to visit that directory:

ln -s /mnt/backup /home/biotech/backup
cd /home/biotech/backup
pwd

This will show "/home/biotech/backup" instead of "/mnt/backup". This happens on both Ubuntu and Cygwin.

What command can I use to see the latter, the "real" directory?

link|improve this question
feedback

4 Answers

up vote 8 down vote accepted

perheps:

pwd -P

from help:

"-P : The pathname printed will not contain symbolic links. "

link|improve this answer
Freudian slip there? – Dan Carley Jun 29 '09 at 14:54
@Dan C - right. but it's fixed now ;-] [ hopefully ] – pQd Jun 29 '09 at 14:55
Haha. I saw it before the edit and was a bit confused. – Dan Carley Jun 29 '09 at 14:57
feedback
/bin/pwd

It doesn't know where you've been or how you got there, so it works it out from first principles.

link|improve this answer
Which environment does this work in? For me on OSX, "which pwd" = /bin/pwd, so calling it directly makes no difference. You need the -P flag. – Steve Bennett Jan 24 at 0:10
Anything sane - which apparently does not include Mac OS X. I've just tried it, and to my complete and utter horror, your observation is correct. I hate being nannied like that. It is completely obnoxious. Somehow, /bin/pwd is being told how you did your cd (on MacOS X). That is so infuriating I can hardly type coherently. Pusillanimous! Butchery of civilized system. Grrrrrrr!!!!!!!!!!!!!!!!!! (The exact same test on a Linux worked as stated. Linux is sane. And I mainly use MacOS X; I don't get this infuriated with it easily.) – Jonathan Leffler Jan 24 at 0:18
what's insane about a command behaving consistently regardless of where it's located? – Steve Bennett Jan 24 at 0:20
It means I have to unlearn close to 30 years of sane behaviour and start mapping it to handle a system that deviates unnecessarily from the path of the old ones (like me). I've no particular problem with the shell knowing how I got to a specific directory, though that sometimes annoys me to. I have major problems with a command like /bin/pwd telling me how it got to the directory; it should work out where it is in the directory hierarchy. Basically, I've now got to know how to find out the real path on MacOS X differently from everywhere else. Which is an utter pain for portability. – Jonathan Leffler Jan 24 at 0:23
And, just for the record, it is MacOS X (maybe BSD) vs 'the rest'; HP-UX, AIX, Solaris and Linux all behave as documented here. And if I had to guess, so will plain BSD; I'd lay odds it is a Mac-only 'feature' (full pejorative intent completely intended!). – Jonathan Leffler Jan 24 at 0:30
feedback

To solve this problem for the general case (i.e. not just current directory), use:

readlink -f PATH
link|improve this answer
feedback

From the shell.

pwd -P

From userland.

/bin/pwd
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.