Is it possible to use ! to re-run a bash command line that starts with a digit? I know that, normally, !<digit> selects a command by position, and !<text> selects a command by text. I am wondering if the <text> interpretation can be forced.

My use case is 7-zip, /usr/bin/7z. I frequently do 7z e *.zip in whichever directory I happen to be in. I can't use !7 to retrieve that command, in general. My workaround is to use CtrlR and interactive history search.

I looked on Google, and I tried ! 7, !\7, !'7', and !"7", without success. Is there a way? Thanks!


1 Answer 1




will search the entire command line of history entries for string, rather than just matching on the start-of-line, so can be used to match commands beginning with a digit n without being interpreted as referring to the nth entry in history.

If additional history modifiers are to be added, the search string must also be terminated with a ?, but in the event of a simple search-and-execute, the trailing ? is optional.

You must log in to answer this question.

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