Life In The Stack Trace...

TODO: <Insert clever marketing phrase here>

How do I get the cd command to follow symbolic links to the physical directory?

Use the -P option to tell cd to change directory to the physical directory where the symbolic link is pointing.

Example

target directory: /mydata/apps/tools/myconfig home directory with symbolic link: /home/user/myconfig -> /mydata/apps/tools/myconfig

cd ~
cd myconfig
# pwd displays /home/user/myconfig

cd ~
cd -P myconfig
# pwd displays /mydata/apps/tools/myconfig

I know of two ways you can make the cd command change to the physical directory.

  1. create a command alias: alias cd='cd -P'

  2. set -o physical

This is how I did it. My distro is Ubuntu. I added an alias to ~/.bashrc

  • nano ~/.bashrc
  • add alias cd='cd -P'
  • save
  • logout and login again