4

If I have in current directory a file with a long name starting with "build" I can write in console "build", press Tab and autocomplete type full filename for me. However if I have multiple files starting with build the autocomplete doesn't work - it simply gives me a list of files starting with build.

In contrary in Windows pressing Tab key immediately gives to me full file name of the first file and if I press Tab key second time it gives me second file name.

How to autocomplete filenames in Linux like in Windows? PS: Its really terrible if I have several long filenames that differ by extension only.

3 Answers 3

4

If they differ by extension only the autocomplete will autofill all untill there are multiple options. When tabbing yields a list of names, type the next character and hit tab again to resume auto completing.

As I'm linux minded I really have fights with the way windows autocomplete works, guess it's what you're used to ;)

5

Something that is a life-saver for me is to have bash cycle through the possibilities instead of showing a dumb list.

As bash is using readline for its auto-completion, add the following lines to ~/.inputrc

Once you're satisfied and have thoroughly tested below solution for a few days/weeks, cut and paste (don't copy!) the same settings from ~/.inputrc to /etc/inputrc which contains the system-wide settings, making this available to all users on your system.

The codez:

# mappings to have up and down arrow searching through history:
"\e[A": history-search-backward
"\e[B": history-search-forward
# mappings to have left and right arrow go left and right: 
"\e[C": forward-char
"\e[D": backward-char

# mapping to have [Tab] and [Shift]+[Tab] to cycle through all the possible completions:
"\t": menu-complete
"\e[Z": menu-complete-backward

then exit your terminal (or remote terminal like putty) and open it again...

Examples:

  1. When you have 3 files: file1, file2 and file3 and you type:

    e fTabTabTab

    it'll cycle forwards through:

    e file1
    e file2
    e file3
    

    and when you want to cycle backwards, just hit Shift+Tab

  2. When you type:

    very-complicated-command with lots of command line parameters
    

    and next time you need the same command, you just type:

    very

    and it'll type for you:

    very-complicated-command with lots of command line parameters
    

This will save you a ton of time in bash! ;-)

Source

2

You have 2 options:

1) You can type one more letter in and tab again

2) Use a shell with better completions. I use zsh, but fish has amazing (somewhat better) completions as well

For zsh, check out oh-my-zsh

EDIT: At least on the default zsh Config, you need to tab twice before it starts cycling through the options

You must log in to answer this question.

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