While none of us gets the respect he or she deserves, Unix at least
listens and remembers what we say-as witnessed by the C and K
shell's history command. This command not only recalls your
previous commands but also lets you re-execute and even repair them
(better than going around saying, ``Gee I wish I had said that.''):
% history You issue the history (or his) command. 30 ls Here's your list. 31 cd comphy/book/chapters 32 ftp bigblue 33 mail 34 print malebox 35 history The history command above. %
Notice that the commands are listed in the numerical order in which they have been issued during the present login. As a result, the last one, number 35, is at the bottom of the list. Some uses of this list are:
!!
!n
!pattern
^ old^ new^
!n:s/old/new/
r
r n
r pattern
Here are some examples which show that if you know history, you may relive it:
% history Tell me my last commands. ls This is the 30th command since login.
history Unix tells you what's going on.
- cd comphy/book/chapters Here's your history again.
history 2 history's since you repeated it.
% !31 Repeat command #31.
31 cd comphy/book/chapters Unix tells you what's going on.
% Your turn.
% !f Repeat previous f... command.
32 ftp bigblue Command #32 is being repeated.
^ male^ mail^ Correcting spelling of male.
print mailbox Corrected command.
% !31/book/BOOK Rerun # 31, substitute for book.
% cd comphy/BOOK/chapters The corrected command.
Next: Command Line Editing
Up: Interactive Shell Tips
Previous: Interactive Shell Tips