C-Shell History Command

Event designators

# Begin a history substitution
!
# Previous command
!!
# Command number n in history list
!n
# n th commnand back from current command
!-n
# Most recent command that starts with string
!string
# Most recent command that contains string
!?string[?]
# Quick substitution, change string old to new in previous command, and execute modified command
^old^new^

Word substitution

# Command name
:0
# Argument number n
:n
# First argument
^
# Last argument
$
# Argument matched by a !?string? search
%
# Arguments n through m
:n-m
# Words 0 through m, same as :0-m
-m
# Arguments n through next-to-last
:n-
# Arguments n through last; same as n-$
:n*
# All arguments; same as ^-$ or 1-$
*

History modifiers

# Display command, but don't execute
:p
# Substitute string new for old, first instance only
:s/old/new
# Substitute string new for old, all instances
:gs/old/new
# Same as :gs
:as/old/new
# Apply the substitution to all words in the command line
:Gs/old/new

Usage

touch test1 test2
echo !:0 !t:1!t:2
mkdir !t:1!t:2
mv !t:1 !t:2 !m:$

!t:p
!t:p:s/test/TEST
!t:p:as/test/TEST
!t:p:Gs/touch/ls