--> --> History lists -->

History lists

Csh provides a list of commands that you have typed in, as well as a rich set of designators and modifiers. The size of the history list is controlled by the history variable. Each entry in the history list, known as an event, is numbered sequentially, however the start of the list does not necessarily start at zero, since old events are removed from the list once the number of events reach the value of the history variable. You can specify previous events by its absolute number, its relative number to the current event, or a sub-string matching all or part of a previous event. You use a ! character (also called a bang) to specify a history event.

You recall a previous event by its number using:

!n
where n is the event number by it's relative number to the current event;
!-n
where n is the nth previous event.

by a sub-string beginning an event name on the history list
!<string>, where string begins an event on the list. It is not necessary to specify the whole word (or command name), just enough to specify the one you want. If it matches more than one event, the shell will use the most recent event.

by a sub-string of an event
!?<string>?, where string is appears in any part of a previous event. Again, it is not necessary to specify an entire word, and duplicate matches will get you the most resent event.

to execute the last command you can simply type: !!

A string in the above selectors is a word, not a string of words. When you use !command x, x becomes an argument following the history completion of !command.

For some examples, we first need a history list, so suppose we have:

19      emacs ~/private/resume
20      ls docs/politics
21      more docs/politics/U.S.house.email.addresses
22      mail georgia6@hr.house.gov
23      telnet wam
!21
would repeat the command more docs/politics/U.S.house.email.addresses
!m
would repeat the command mail georgia6@hr.house.gov, since we only used m, it found the first command that started with m, to specify the last more command we would use !mo.
!-5
would recall the emacs command, since that is 5th last command we typed.
!?priv?
would recall the emacs command, since that is the last command that contained the word priv (i.e. private).
How do I:
How are we doing? Comments on this page?
Office of Information Technology
Office of Information Technology Help Desk Web Site University of Maryland Web Site Office of Information Technology Web Site