Main index

Introducing UNIX and Linux


Processes and devices

Overview
Processes
      Process status
      Foreground and background
      Process control
      Signals
Environment
      Environment variables
      Global and local variables
      Executable scripts
Program control
      Job control
      Command history list
      Running a job at a specific time
      Running programs periodically
      Big programs
      Timing a program
      Running programs in order
Quotes and escapes
Devices
Backquotes
Summary
Exercises

Command history list

UNIX keeps a record of the commands you have typed in to your shell. Each command is given a number, starting with 1, and using the command fc ('fix command') you can re-execute previous commands. To list the commands you have already run, use option -l ('list'):

fc -l
1      date
2      sh myalarm &
3      mailx sam

If you run fc with no arguments, the shell first of all creates a temporary file (you don't need to know its name) containing one line, namely the last command you ran. In the above example, this would be

mailx sam

The shell would then run Vi on that file without you having to type vi yourself. You can then edit that file, thinking of it as a script of commands to be run - you can change the last command you ran, or add extra commands to the file. When you leave Vi, whatever is in that temporary file will be treated as commands to the shell and run immediately. Note that if, when leaving the editor, there is more than one line in the temporary file, each line in the file will be executed separately and in turn. An fc command is not itself entered in the history list. You can select a number of commands by specifying the first and last numbers of the commands you have already run - so to rerun commands 2 through 4 and edit them,

fc 2 4

will create a file containing three lines and then apply vi to that file. Often you will simply wish to re-run commands you have previously typed in without editing. Using option -s ('string') this can be accomplished. In the above example, to re-run the alarm, you could just have

fc -s 3


Copyright © 2002 Mike Joy, Stephen Jarvis and Michael Luck