The crude Bash history expansion cheatsheets I handcrafted for my desk-atop wall

Bash
History expansion

!

!n

!-n

!! (!-1)

!str

!?str[?\n] — containing

^str^str^ — equiv. to !:s^str^str^

!#: typed so far, entire

Word designator

:0 command word
:n nth arg
^ word 1
$ word minus one (last)
% first word that matched "containing"
:m-n range of words
-n
:0-n
*-
:1-$
:x*
:x-$
:x-
x to without last

 

:h
directory (head)
:t
only file name (tail)
:r
without.xxx
:e
only .xxx
:p
dry run
:q
quote subs
:x
quote but break
:
[gG]s
D…
D
…[D/endl]
&
→ null → & → prev
:&
same sub
History expansion supplement same table
                but hand-crafted
!$
last arg last command
!^
first arg last command
!-2:0^ subcmd name of previous last
!?git commit -am?:3 commit message
ls .. !#$/.. !#$/.. !#$/.. typed so far
!!- command w/o last arg
!!
g
G
s`HEAD`&^
swap "HEAD" for "HEAD^"
!?ommi?:p then !:0 !%
after dry run search for 'commit' command word and matched word
ls !$:h visit file's directory !$:t filename tail
head !$:t:r w/o dot suffix (any leng)
!* only args (set -Ho history) in scripts
^O to advance