I have a directory containing a disk image, let's call it "image.dd". In reality it is a much longer name, thus the desire to table complete the name by typing the first character and hitting tab to get the rest. There are only a few files in the directory, each starting with a unique letter.

If I type ls i<TAB> the command completes properly to ls image.dd.

But if I type fdisk -l i<TAB> nothing happens. This is really annoying. I get the impression that tab completion is snooping on my command and seeing the "fdisk" part and saying, "Oh, you can't fdisk a regular file, so I'm going to ignore your request to autocomplete the file, even though it is actually there."

Of course when I manually type in the name it works, I can fdisk a file when it's a disk image, so how can I get tab completion to just work?

Using Ubuntu 16.04, bash version is 4.3.42.

  • Tab completion works for me on a 14.04 server installation in both examples you've given.
    – Arronical
    Jan 25, 2017 at 18:21
  • @Arronical updated question to include versions I am using.
    – Michael
    Jan 25, 2017 at 18:58

1 Answer 1


The complete rules for fdisk are stored in the file /usr/share/bash-completion/completions/fdisk. The rules there defines that it will expand to block devices. To overwrite this setting in your current enviroment - you could do:

complete -F _filedir_xspec fdisk

You could add this to your .bashrc file.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .