home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


Book HomeBook TitleSearch this book

5.5. Command History

Previously executed commands are stored in a history list. The C shell lets you access this list so you can verify commands, repeat them, or execute modified versions of them. The history built-in command displays the history list; the predefined variables histchars, history, and savehist also affect the history mechanism. Accessing the history list involves three things:

  • Making command substitutions (using ! and ^)

  • Making argument substitutions (specific words within a command)

  • Using modifiers to extract or replace parts of a command or word

5.5.2. Command Substitution Examples

The following command is assumed:

3% vi cprogs/01.c ch002 ch03
Event NumberCommand TypedCommand Executed
4^00^0vi cprogs/01.c ch02 ch03
5nroff !*nroff cprogs/01.c ch02 ch03
6nroff !$nroff ch03
7!vivi cprogs/01.c ch02 ch03
8!6nroff ch03
9!?01vi cprogs/01.c ch02 ch03
10!{nr}.newnroff ch03.new
11!!|lpnroff ch03.new | lp
12more !?pr?%more cprogs/01.c

5.5.4. Word Substitution Examples

The following command is assumed:

13% cat ch01 ch02 ch03 biblio back
Event NumberCommand TypedCommand Executed
14ls !13^ls ch01
15sort !13:*sort ch01 ch02 ch03 biblio back
16lp !cat:3*lp ch03 biblio back
17!cat:0-3cat ch01 ch02 ch03
18vi !-5:4vi biblio

5.5.6. History Modifier Examples

From the table in Section 5.5.4, command number 17 is:

17% cat ch01 ch02 ch03
Event #Command TypedCommand Executed
19!17:s/ch/CH/cat CH01 ch02 ch03
20!:g&cat CH01 CH02 CH03
21!more:pmore cprogs/01.c (displayed only)
22cd !$:hcd cprogs
23vi !mo:$:tvi 01.c
24grep stdio !$grep stdio 01.c
25^stdio^include stdio^:qgrep "include stdio" 01.c
26nroff !21:t:pnroff 01.c (is that want I wanted?)
27!!nroff 01.c (execute it)



Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.