Using the history feature of Unix to save typing

The history feature of Unix

The UNIX system keeps a history of the commands that you have entered recently. You can look at this list by typing the command history at the frodo% prompt.

Recalling previous commands
You should notice that each of these commands has a number next to it, which represents the order in which these commands were called after you logged on. You can actually redo any of these commands by typing in ``!'' followed by that number. For example, to execute command number 7 on the list, you would type in

	!7

This could save time and effort if that command were long or complex.

You can also use the ``!'' in other useful ways. Typing in

	!!

redoes the last command entered. So does !-1. In general, typing !-N, where N is some positive integer, executes the Nth-from-last command entered.

Searching for previous commands
Still more useful in UNIX's ability to search through its history for certain command patterns, which is done if you follow the ``!'' with letter characters. UNIX searches for the most recent instance of a command which started with those letters, and executes it. For example, if you typed

	!pico

UNIX would search for the most recent call to pico and execute it. Again, this can save you time and effort. As you know by now, debugging a program usually involves a long cycle of editing, compiling, and running a program. The commands for each of these can be shortened by using this search. For instance, if you had previously typed the commands:

pico newprogram.cc
g++ newprogram.cc
a.out

then the next time around you could do the same thing by typing:

!pi (this would execute pico newprogram.cc)
!g (this would execute g++ newprogram.cc)
!a (this would execute a.out)

Note: If the history commands do not work, you may need to add the following command to the end of your .login file:

set history=50

When you login in the future, Unix will keep track of the last 50 commands entered during that session.