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.
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 abreak
after the unzip it continues to ask until one enters Ctrl+C.