I created a soft link (ln -s 1 2) to a directory which is inside the test directory and opened the soft link (cd 2) and displayed the current path using pwd. The displayed path was ~/test/2 and not ~/test/1.

It's different in an OS like Windows, the shortcut brings us to the real directory. I'm little bit confused how this soft link works in Linux. Is it not a shortcut like in Windows? Why is the path not ~/test/1?

 $ mkdir test
 $ cd test
 $ mkdir 1
 $ ln -s 1 2
 $ cd 2
 $ pwd
  • 2
    Thanks for removing the screenshot. Next time, please edit your question instead of deleting and reposting. Deleting too many of your own questions can get you banned from asking. That ban is automatic so we won't be able to do much about it. In any case, you don't need to repost since editing bumps the question.
    – terdon
    Apr 16, 2015 at 17:29
  • Why do you ask twice? askubuntu.com/q/610133/367165
    – A.B.
    Apr 16, 2015 at 17:30
  • A.B same forum?
    – DScript
    Apr 16, 2015 at 17:53

3 Answers 3


That is a feature of the shell that remembers how you got to where you are.
If you have realpath installed you can do:

$ realpath 

And lacking that if you have python:

$ python -c "import os; print(os.path.realpath('.'))"

or readlink (from coreutils):

$ readlink -f .

or /bin/pwd (not the shell built-in pwd):

$ /bin/pwd
  • ls -l /proc/$$/cwd takes advantage of the kernel's /proc filesystem interface.
    – user732
    Apr 16, 2015 at 19:01
  • 10
    Note also pwd -P to print the physical, instead of logical, path to the current directory.
    – godlygeek
    Apr 16, 2015 at 21:17
  • GNU coreutils now includes a realpath that requires an explicit file argument, unlike BSD realpath (and presumably others?) which default to . as the file argument when none is provided Sep 21, 2021 at 19:44

Contrast pwd and /bin/pwd.

pwd, which is a built-in command in many shells, tells you where your shell thinks you are (and hence treats symlinks "soft links" as if they were real directories.

/bin/pwd is an external program that tells you where you really are, if necessary by traversing the filesystem tree up to /. It takes no account of symlinks because those don't exist when traversing upwards through ..


Other answers have covered /bin/pwd vs the shell's builtin pwd.

If you want to follow symlinks in the Windows style you mentioned, use cd -P: it will change the PWD variable accordingly.

If you want to use -P by default, you can add this line to your .bashrc or .zshrc:

set -P

Other shells may vary.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .