When I use standard tab completion in bash or zsh, I type the first part of a filename or path, then hit to complete the word. This works well unless I'm in a directory full of files where all of the variation in filenames is at the end of the word, e.g. A directory full of time-stamped files which all start with the same prefix:


In this case, if I type foo<tab> I'll get foo-20120701124 -- I can tab again, and see all of the files... I would have to type in the next 3 characters to get to a unique file name.

I'm wondering if there is a way to type for instance 4731.log and then complete beginning of the word. I'm guessing that this would be difficult in bash, because bash completion uses $COMP_CWORD and $COMP_KEY for its programmable completion, and from the way that I'm reading it, I don't think that those would allow for leftward word completion. I don't know enough about completion inside zsh to know where to start looking in the man pages.

1 Answer 1


This will only work if there is a leading command before hitting tab. Likely is not what you are looking for but the only was I could get the desired results. The below example should work in your case. You just need to be at the end of the *4731.log and hit tab 1 time. If it is unique it will autocomplete.

ls *4731.log
  • Yep, worked like a charm. I generated a series of files using for i in {1..10}; do touch $(date -d "$i days $RANDOM seconds ago" +%Y%m%d%H%M%S); done... this created a series of files which looked like 20120915165427 20120916121328 20120917180952 etc. If I use ls *09<tab>, it doesn't expand, but *09*<tab> does. Commented Sep 15, 2012 at 1:05

You must log in to answer this question.

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