Something is wrong with my tab completion.

Let's say I do this:

cd test // works fine, go into test directory
ls // works fine, displays all of the files

Let's assume I have the following files:


If I type a and then TAB for auto complete, it displays something different like:

... // bunch more

I feel like it thinks I'm in a different directory?


Those are commands. If you start typing on the commandline and hit Tab, it won't expand the subdirectories and files of your location but available commands.

Basically, tab completion is context sensitive. If you just start writing and hit Tab, it will complete commands found in your $PATH. If you have already written a command, cd for example, it will complete the files and directories in your current location. For some commands, it will also complete available options to that command.

  • 1
    Note that the "double tab" while entering a path may match the OP behavior expectation: it will list all the files available in the currently displayed directory. – Laurent C. Mar 6 '14 at 15:18
  • 2
    @LaurentC. only if you have set ./ to be in your $PATH and even then, only the executable files. – terdon Mar 6 '14 at 15:20

Bash completion does not work as you expect. I will try to give a rough explanation.

When you are typing a command (or if you haven't written anything yet) and press the tab key, bash try to complete with any of the available commands on your $PATH (a2p and a2x are just two commands). Once you have written your command, if you press the tab key again it will try to complete with the arguments for that command (the directory test in your example is an argument to cd).

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.