Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a symlink:

/path/to/foo -> /path/to/bar/foo

When in /path/to/foo I might want to cd to /path/to/bar/foo:

$ cd ../ Tab

Then nothing autocompletes. I can still cd just fine by typing in the directory "bar", though.

Why is that? Is there a setting or trick I can apply to have that tab-complete too?

share|improve this question

This is a bug in bash-completion (a third-party project, not affiliated with bash itself). /etc/bash_completion is sourced in ~/.bashrc by default in Ubuntu, and amongst the thousands of lines of code (most of which you likely never need), is a completion function for the cd builtin that doesn't handle symlinked directories properly. If you disable its completion for the cd builtin, your tab-completion for cd should work more like you expect.

complete -r cd
share|improve this answer

I think this is by design and how Bash handles the present working directory.

Compare the outputs of:

  1. pwd
  2. pwd -P

(The latter displays the physical current working directory instead of the symlinked one. Pwd manual.)

You can make Bash to always use the physical working directory by using:

set -P

The manual states:

-P If set, the shell does not follow symbolic links when executing commands such as cd that change the current working directory. It uses the physical directory structure instead. By default, bash follows the logical chain of directories when performing commands which change the current directory.

As a side effect, when you cd /path/to/foo, your pwd will be: /path/to/bar/foo.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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