Which command in the Linux/UNIX sh shell returns my current directory?

Try pwd.

$ pwd
/home/<username>

While the general answer is pwd, note that this may give different results depending on how you reached a given directory, and whether the route included symbolic links.

For instance, if you have a directory called real and a symbolic link to that directory called virtual, and you cd to the virtual directory, then pwd will show that virtual directory name, even though the actual directory you are in is real.

To show the real underlying directory, use either pwd -P or readlink -f (for a arbitrary path):

$ mkdir real
$ ln -s real virtual
$ cd virtual
$ pwd
/home/username/tmp/virtual
$ pwd -P
/home/username/tmp/real
$ readlink -f .
/home/username/tmp/real

Note that shells often replace the pwd command with their own internal version, so on my system (RHEL6), even though the pwd(1) manual page suggests that --physical will work as well as -P, because I'm running bash, it doesn't:

$ pwd --physical
bash: pwd: --: invalid option
pwd: usage: pwd [-LP]
$ /bin/pwd --physical
/home/username/tmp/real
$ /usr/bin/env pwd --physical
/home/username/tmp/real

Tags:

Linux

Sh