Q:

Shortcut to return realpath of the symlink?

Is there any shortcut to return actual path of the symlink?
like : I have created a symlink in home
$ cd
$ ln -s /home/usr/workspace/helloworld/datadir datadir
$ ls -l

lrwxrwxrwx  1 usr usr    10 Mar  5 16:57 datadir -> /home/usr/workspace/helloworld/datadir

Now, 
$ cd datadir
$ pwd
/home/usr/datadir

Here is there any way get back to  /home/usr/workspace/helloworld/ directory without typing whole path
$ cd ../ 

This takes me back to home directory!

A:

Try this command,
readlink -f $(pwd)

readlink reads the contents of a symlink, and readlink -f follows symlinks to symlinks to symlinks, etc., until it finds something that isn't a symlink.
So,
cd $(readlink -f $(pwd))

OR
cd $(readlink -f .)

The above commands allows you to go into the original directory.
Example,

~/Desktop$ ls -l
lrwxrwxrwx 1 avinash avinash        22 Mar  4 14:11 Pictures -> /home/avinash/Pictures

~/Desktop$ cd Pictures
~/Desktop/Pictures$ pwd
/home/avinash/Desktop/Pictures

~/Desktop/Pictures$ readlink -f $(pwd)
/home/avinash/Pictures

~/Desktop/Pictures$ cd $(readlink -f $(pwd))
~/Pictures$ 

