Command history lets you repeat a previous command, access data
about a previous command, or display a list of previous commands.
You reference a previous command by starting a command with an exclamation point, and either the first letters of the command, a star and string from anywhere in the command, the number of the history entry, or blank for the last command:
mpsh$ !command mpsh$ !*arg mpsh$ !n mpsh$ !
You can retrieve history information by adding a dot and field name to a history reference. This displays the field you requested, rather than repeating the command. The available fields are:
num - The history entry number.
Instead of executing a previous command, mpsh will simply display the requested data about the previous command. For example:
Go to the directory that you last used vi in:
mpsh$ cd (!vi.dir)
Look at the detailed history entry for the last invocation of gcc:
mpsh$ history (!gcc.num)
Subsitute "http" for "https" in the last "wget" command, and then execute it:
mpsh$ (!wget.text | sed s/https/http/)
Check to see that your last command expanded the way you expected:
The history command displays previous commands. You can display the short form, long form, user-specified format, or full details for one entry. ("history" with no arguments is short for "history -s".)
mpsh$ history [n] mpsh$ history -s [n] mpsh$ history -l [n] mpsh$ history format-string [n]
The fields displayed by the history command are controlled by format strings, one letter for each field. The simple "history" display is controlled by the mpsh-hist-disp environment variable (default: nc, for: number, command text), and the long format is controlled by the mpsh-hist-disp-l environment variable (default: nusxc, for: number, user cpu time, system cpu time, exit condition, command text). You can also specify a new format as the argument to history. The fields available via the format strings are:
c - Command
To display the commands executed in a particular directory (something including "local" in this example), invoke history with a format string of "dc" to display just directories and commands, and send the output to grep:
mpsh$ history dc | grep local
Display the commands that didn't exit ok:
mpsh$ history xnc | grep -v ^ok
Add start time and exit status to the default history display:
mpsh$ setenv mpsh-hist-disp=ntxc
The width of the fields displayed changes depending on the data, so don't try to filter the output of history based on strict character position.
Clear history with the -c option:
mpsh$ history -c
("history -c" will not delete any entries for commands that have not yet exited. Stopped jobs and still running jobs will remain.)