0

Is there a way to get a list of files in a directory while you're typing something into the command line? E.g. you're typing /var/log/, and at this point you'd like to get a list of files, but without expanding the currently typed command.

The aim is to unzip a file with a fairly long & complex file-name, one file that sits among a few other files, some of them sharing a part of the filename.

What I'm currently doing is after tabbing to expand the command, deleting back to the directory part. (then double-click & right-click the file to copy it into the command, which is fine)

And so I'm wondering if there is a nifty bash keystroke I don't know of. :)

One example (not the actual problem, but similar): you start typing

unzip /var/www/html/mybackups/

and and this point you'd like to get a list of the files so you can select one of them to unzip - but there are 5-10 files - let's say all starting with Program-2020, then some month & day in the filename (not just one each month!), so you can't be sure at any point what the exact filename is, but once you see the list of available ones, you can easily copy/paste it to your command.

The problem is that since there aren't too many files, when you start typing Prog then hit Tab you get something like Program-202006 on the command line, plus the list below - and now you have to pick out which one it is, trying to identify the numbers, trying to type the next correct number- it's sometimes not easy at all. (That's why I use the delete-back method instead)

Apologies if this is a repeat question but I could not find any solution, not even the same question appearing anywhere.

4
  • 3
    I am a bit confused about your requirement. You type "Prog", and tab completion gets you to "Program-202006". You hit Tab once again and you can see a list of files as potential matches for the name. What is blocking you at this point?
    – Haxiel
    Jun 21, 2021 at 5:02
  • Perhaps not what you want, but something in the direction of: select file in /pat/to/*.zip; do read -rp "Unzip '$file' (Ctrl-C to abort) "; echo "the unzip $file cmd"; done - as in select form a numbered list instead of typing file names ... ` - the read confirmation could obviously be removed. If you do not add a a break after the unzip it continues to ask until one enters Ctrl+C.
    – ibuprofen
    Jun 21, 2021 at 6:06
  • As Haxiel said, it sounds like you are just looking for the default behavior of pressing Tab twice. By the way, there's no need to right click to paste, once you have selected something, you can paste it using the middle mouse button.
    – terdon on strike
    Jun 21, 2021 at 9:31
  • @Haxiel my issue is as stated; tab is expanding the command to where the first difference appears, and after that it's pretty difficult to find the correct next character to continue. Tab is not good; the good answer is already posted. Jun 22, 2021 at 6:01

1 Answer 1

2

Looking at the man page for bash, in the Completing section (search for /^\s*Completing$ ) is a list of key bindings and possible key bindings.

The key you are looking for is M-? ("possible completions"). That's Alt+Shift+? or Esc ?

1
  • Awesome, that's it, thanks! Jun 22, 2021 at 5:52

You must log in to answer this question.

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