Command History

The shell's history mechanism allows you to recall previous events (commands) and then repeat them. To enable command history, set the history shell variable in ˜/.cshrc to the number of events that you want the shell to remember. To preserve your history across logins, set the savehist shell variable.

The history command displays your current history:

history          Display entire history list
history n        Display last n events from history list

History Event Specifiers

History references begin with a ! character. When the shell sees such a reference, it replaces it in the command line, echoes the resulting command, and executes it.

The event specifiers listed below select commands from the history list:

Specifier

Description

!!

Repeat previous command

!n

Repeat command n

!-n

Repeat n-th-to-last command

!str

Repeat last command beginning with str

!?str?

Repeat last command containing str

!#

Repeat the current command line typed so far

Word Designators

The word designators listed below extract particular words from an event:

Designator

Description

0

Word 0 (the command name)

n

Word n (argument n)

^

Word 1

$

Last word

m-n

Words m through n

-n

Words 0 through n

m-

Words m through (but not including) last word

-

Words 0 through (but not including) last word

m*

Words m through last word

*

Words 1 through last word, or empty if there are no arguments

%

Following a !?str? event specifier, the word matched by str

Word designators are usually separated from the preceding event specifier by a colon. However, some shortcuts may ...

Get Using csh & tcsh now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.