Unix Concepts   «Prev 

Sampling of Word Substitutions in Unix

Because word substitution syntax provides so many choices, typical users find it faster to just retype an entire command, rather than trying to remember the correct syntax. But the simplest word substitutions, listed below, are worth remembering:

Substitution What it substitutes
!$ Last argument of previous command
!^ First argument of previous command
!* All arguments of previous command

Here are some examples.
They assume that you have just entered this command, which displays the contents of four files named w, x, y, and z:
% cat w x y z

Word substitution in the next command

If you used word substitution in the next command, here’s what would happen:
Next command after cat w x y z Actual command produced
% ls –l !$ % ls –l z
% ls –l !^ % ls –l w
% ls –l !* % ls –l w x y z