Re-Executing Commands
 
 
 
  
  
  
  
 
 Next:  Command Line Editing 
Up:  Interactive Shell Tips
 Previous:  Interactive Shell Tips
 
 
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:
 
  REPEAT COMMANDS  
-  !! 
- Repeat last command (csh).  
-  !n 
- Repeat command number n (csh). 
-  !pattern 
- Repeat command starting with pattern (csh). 
-  ^ old^ new^  
- Change old to new in last command.
-  !n:s/old/new/ 
- Repeat command n with substitution (csh). 
-  r 
- Repeat last command (ksh). 
-  r n 
- Repeat command number n (ksh). 
-  r pattern 
- Repeat command starting with pattern (ksh). 
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.   
 cd comphy/book/chapters   	   
 ftp bigblue   	   
 mail   	   
 print malebox   	   
 history   	This is the command given last.   
%    	Your turn.   
% !!   	Repeat last command (or r).   
-  history   	Unix tells you what's going on.   
-  cd comphy/book/chapters   	  Here's your history again.   
ftp bigblue mail   	   
 print malebox   	   
 history   	   
-  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