I don't know when this started happening but now, every time I cd to a directory it echoes the path right before it changes directories. This happens when I log into a server but doesn't happen on my local machine. The server is running Linux. My local machine is running Mac OS X.

I searched the Google as well as looked at the bash man page but I couldn't find anything. My .bashrc/.bash_profile doesn't have anything related to 'cd' (that I know of).

How do I modify this "feature"?


The shell auto-echoes because CDPATH is defined as an environment variable. If you UNSET CDPATH the default cd behavior will appear again.

  • THANK YOU. Spent hours trying to figure out why a java program that was being called by a node.js script wasn't running. Turned out there was a shell script there somewhere and because my CDPATH was exported in my profile, output of $(cd directory && pwd) printed out /path/to/directory /path/to/directory. – Igor Zevaka Feb 20 '14 at 4:14
  • @DaveParillo fyi, link is broken – mtk Jun 8 '16 at 9:37

The above answer suggesting to unset CDPATH is probably the best. However, if you want CDPATH to remain active while cd-ing you can also use in your scripts something like:

cd /path/to/wherever > /dev/null


Another option is to more permanently override the builtin cd with a bash function. I've found something like this effective when placed in your ~/.profile (or similar) file:

function cd() {
    if [ -z "$*" ]; then 
    builtin cd "${destination}" >/dev/null && ls
  • This preserves the use of cd without arguments to return to your home directory.
  • The >/dev/null is responsible for swallowing the folder name being echoed. (That echoing of the folder name is what breaks scripts that use FOO=$(cd $SOMEVAR && pwd) to save a full path to a variable.)
  • And finally; as written this function performs an automatic ls after changing directories. (Remove the && ls to stop that.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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