|Developer(s)||Various open-source and commercial developers|
|Operating system||Unix, Unix-like, PTS-DOS, Windows, ReactOS, KolibriOS|
In computing, various shells maintain a record of the commands issued by the user during the current session. The
history command works with the command history list. When the command is issued with no options, it prints the history list. Users can supply options and arguments to the command to manipulate the display of the history list and its entries. The operation of the history command can also be influenced by a shell's environment variables. For example, an environment variable can be set to control the number of commands to retain in the list.
In early versions of Unix the history command was a separate program. However, most shells have long included the history command as a shell built-in, so the separate program is no longer in common use.
The command is available in various Unix shells, as well as in PowerShell, ReactOS, and KolibriOS. It is also included as external command in PTS-DOS where it keeps a resident part, sometimes in conventional memory.
Since most current history commands are shell built-ins, details depend on the choice of shell.
history command has the following syntax in bash:
history [-c] [-d offset] [n] history -awrn [filename] history -ps arg [arg...]
history command has the following syntax in tcsh:
history [-hTr] [n] history -S|-L|-M [filename] (+) history -c (+)
The first form prints the history event list. If n is given only the n most recent events are printed or saved. With -h, the history list is printed without leading numbers. If -T is specified, timestamps are printed also in comment form. (This can be used to produce files suitable for loading with 'history -L' or 'source -h'.) With -r, the order of printing is most recent first rather than oldest first.
With -S, the second form saves the history list to filename. If the first word of the savehist shell variable is set to a number, at most that many lines are saved. If the second word of savehist is set to `merge', the history list is merged with the existing history file instead of replacing it (if there is one) and sorted by time stamp. (+) Merging is intended for an environment like the X Window System with several shells in simultaneous use. Currently it succeeds only when the shells quit nicely one after another.
With -L, the shell appends filename, which is presumably a history list saved by the -S option or the savehist mechanism, to the history list. -M is like -L, but the contents of filename are merged into the history list and sorted by timestamp. In either case, histfile is used if filename is not given and ~/.history is used if histfile is unset. `history -L' is exactly like 'source -h' except that it does not require a filename.
Note that login shells do the equivalent of `history -L' on startup and, if savehist is set, `history -S' before exiting. Because only ~/.tcshrc is normally sourced before ~/.history, histfile should be set in ~/.tcshrc rather than ~/.login.
If histlit is set, the first and second forms print and save the literal (unexpanded) form of the history list.
The last form clears the history list.
In PowerShell, history is a predefined command alias for the
Get-History cmdlet. In addition, PowerShell includes the
Invoke-History cmdlets. The
*-History cmdlets serve the same purpose as the Unix-like
Get-History [[-Id] <Int64>] [[-Count] <Int32>] [<CommonParameters>] Add-History [[-InputObject] <PSObject>] [-Passthru] [<CommonParameters>] Clear-History [[-Id] <Int32>] [[-Count] <Int32>] [-Newest] [-Confirm] [-WhatIf] [<CommonParameters>] Clear-History [[-Count] <Int32>] [-CommandLine <String>] [-Newest] [-Confirm] [-WhatIf] [<CommonParameters>] Invoke-History [[-Id] <String>] [-Confirm] [-WhatIf] [<CommonParameters>]
ReactOS Command Prompt
history command of the ReactOS Command Prompt currently only supports printing the history list.
- ^ "Using "History" to Repeat Commands". University of Washington. Retrieved 25 July 2013.
- ^ "Reactos/Reactos". GitHub. 3 November 2021.
- ^ "Shell - KolibriOS wiki".
- ^ "PTS-DOS 2000 Pro User Manual" (PDF). Buggingen, Germany: Paragon Technology GmbH. 1999. Archived (PDF) from the original on 2018-05-12. Retrieved 2018-05-12.
- ^ Darwin Kernel Version 15.0.0: Sat Sep 19 15:53:46 PDT 2015
- McElhearn, Kirk (2006). The Mac OS X Command Line: Unix Under the Hood. John Wiley & Sons. ISBN 978-0470113851.