Lets say I have multiple files in a directory which all start with the same string

$ ls
  fileAA234 fileAA247 fileAA255 fileAA264
  fileAA269 fileAA277 fileAA285 fileAA294

Often, when browsing such data files in the command line, I just want to read one, anyone, of these files to see how they are structured.

But if I enter

$ less f 

And then hit tab for completion the answer will be

$ less fileAA2
  fileAA234 fileAA247 fileAA255 fileAA264
  fileAA269 fileAA277 fileAA285 fileAA294

Which doesn't get me all that much closer to open one of the files.

So for now I either use the mouse to mark a random file name and copy paste it to the prompt, or I lean forward and have my poor eyes figure out a unique string to finish typing the filename.

Is their an easy solution for this? I'm just missing something obvious, right? I'd really like to have something like tab+enter to auto complete and open the first file in the list, like in this case fileAA234.

Thanks for any help. I imagine there is a way to build a shell script by combining some tools like ls and head but I'm still a beginner and haven't found a solution myself yet.

2 Answers 2


Just use a wildcard (*):

$ less fileAAA*

That will open the first file in less. When you get to the end of the file, less will continue to the next one. If all you want is a quick look at any one file, and always opening the first (alphanumerically sorted) one is ok, just hit "q" to exit less as soon as you have seen enough.

  • Oh boy, i knew there must be an obvious solution. Thanks a lot! Also works well for directories! Aug 23, 2012 at 12:46

For bash, put the following in ~/.inputrc:

"\C-i": menu-complete

This will cause Tab to always complete full names; press it again to switch between completions

  • Thank you, thats really cool. But now, when I enter $ cd dir/ and hit tab I won't see the list of subfolders anymore. I have to press enter and use ls. Aug 27, 2012 at 20:52
  • @user1323995: Then bind menu-complete to a different key instead of Tab. For example, \C-q for Ctrl+Q, or \e[Z for Shift+Tab. Aug 27, 2012 at 21:31

You must log in to answer this question.

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