History (command)

Last updated
history
Developer(s) Various open-source and commercial developers
Operating system Unix, Unix-like, PTS-DOS, Windows, ReactOS, KolibriOS
Type Command

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. [1]

Contents

History

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.

Implementations

The command is available in various Unix shells, as well as in PowerShell, ReactOS, [2] and KolibriOS. [3] It is also included as external command in PTS-DOS where it keeps a resident part, sometimes in conventional memory. [4]

Since most current history commands are shell built-ins, details depend on the choice of shell.

bash

The history command has the following syntax in bash: [5]

history [-c] [-d offset] [n]  history -awrn [filename]  history -ps arg [arg...]

tcsh

The 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.

PowerShell

In PowerShell, history is a predefined command alias for the Get-History cmdlet. In addition, PowerShell includes the Add-History, Clear-History, Get-History, and Invoke-History cmdlets. The *-History cmdlets serve the same purpose as the Unix-like history command.

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

The history command of the ReactOS Command Prompt currently only supports printing the history list.

See also

Related Research Articles

Bash (Unix shell) GNU replacement for the Bourne shell

Bash is a Unix shell and command language written by Brian Fox for the GNU Project as a free software replacement for the Bourne shell. First released in 1989, it has been used as the default login shell for most Linux distributions. A version is also available for Windows 10 via the Windows Subsystem for Linux. It is also the default user shell in Solaris 11. Bash was also the default shell in all versions of Apple macOS prior to the 2019 release of macOS Catalina, which changed the default shell to zsh, although Bash currently remains available as an alternative shell.

Shell script Script written for the shell, or command line interpreter, of an operating system

A shell script is a computer program designed to be run by the Unix shell, a command-line interpreter. The various dialects of shell scripts are considered to be scripting languages. Typical operations performed by shell scripts include file manipulation, program execution, and printing text. A script which sets up the environment, runs the program, and does any necessary cleanup, logging, etc. is called a wrapper.

Unix shell Command-line interpreter for Unix operating system

A Unix shell is a command-line interpreter or shell that provides a command line user interface for Unix-like operating systems. The shell is both an interactive command language and a scripting language, and is used by the operating system to control the execution of the system using shell scripts.

An environment variable is a dynamic-named value that can affect the way running processes will behave on a computer. They are part of the environment in which a process runs. For example, a running process can query the value of the TEMP environment variable to discover a suitable location to store temporary files, or the HOME or USERPROFILE variable to find the directory structure owned by the user running the process.

In computing, touch is a command used to update the access date and/or modification date of a computer file or directory. It is included in Unix and Unix-like operating systems, TSC's FLEX, Digital Research/Novell DR DOS, the AROS shell, the Microware OS-9 shell, and ReactOS. The command is also available for FreeDOS and Microsoft Windows.

In computing, kill is a command that is used in several popular operating systems to send signals to running processes.

Comparison of command shells Wikimedia list article

A command shell is a command-line interface to interact with and manipulate an computer's operating system.

more (command)

In computing, more is a command to view the contents of a text file one screen at a time. It is available on Unix and Unix-like systems, DOS, Digital Research FlexOS, IBM/Toshiba 4690 OS, IBM OS/2, Microsoft Windows and ReactOS. Programs of this sort are called pagers. more is a very basic pager, originally allowing only forward navigation through a file, though newer implementations do allow for limited backward movement.

In computing, tee is a command in command-line interpreters (shells) using standard streams which reads standard input and writes it to both standard output and one or more files, effectively duplicating its input. It is primarily used in conjunction with pipes and filters. The command is named after the T-splitter used in plumbing.

In computing, exec is a functionality of an operating system that runs an executable file in the context of an already existing process, replacing the previous executable. This act is also referred to as an overlay. It is especially important in Unix-like systems, although it exists elsewhere. As no new process is created, the process identifier (PID) does not change, but the machine code, data, heap, and stack of the process are replaced by those of the new program.

PowerShell Cross-platform command-line interface and scripting language for system and network administration

PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and the associated scripting language. Initially a Windows component only, known as Windows PowerShell, it was made open-source and cross-platform on 18 August 2016 with the introduction of PowerShell Core. The former is built on the .NET Framework, the latter on .NET Core.

move (command)

In computing, move is a command in various command-line interpreters (shells) such as COMMAND.COM, cmd.exe, 4DOS/4NT, and PowerShell. It is used to move one or more files or directories from one place to another. The original file is deleted, and the new file may have the same or a different name. The command is analogous to the Unix mv command and to the OpenVOS move_file and move_dircommands.

ren (command)

In computing, ren is a command in various command-line interpreters (shells) such as COMMAND.COM, cmd.exe, 4DOS, 4NT and Windows PowerShell. It is used to rename computer files and in some implementations also directories. It can also move a file to a new path, if it is on the same device. It is analogous to the Unix mv command. However, unlike mv, ren cannot be used to move files, as a new directory for the destination file may not be used. Alternatively, move may be used if available. On versions of MS-DOS that do not support the move command, the user would simply copy the file to a new destination, and then delete the original file. A notable exception to this rule is DOSBox, in which ren may be used to move a file, since move is not supported.

TYPE (DOS command)

In computing, type is a command in various command-line interpreters (shells) such as COMMAND.COM, cmd.exe, 4DOS/4NT and Windows PowerShell used to display the contents of specified files on the computer terminal. The analogous Unix command is cat.

del (command)

In computing, del is a command in command-line interpreters (shells) such as COMMAND.COM, cmd.exe, 4DOS, NDOS, 4OS2, 4NT and Windows PowerShell. It is used to delete one or more files or directories from a file system.

In computing, pushd and popd are commands used to work with the command line directory stack. They are available on command-line interpreters such as 4DOS, Bash, C shell, tcsh, Hamilton C shell, KornShell, cmd.exe, and PowerShell for operating systems such as DOS, Microsoft Windows, ReactOS, and Unix-like systems.

help (command) Command in various command line shells

In computing, help is a command in various command line shells such as COMMAND.COM, cmd.exe, Bash, qshell, 4DOS/4NT, Windows PowerShell, Singularity shell, Python, MATLAB and GNU Octave. It provides online information about available commands and the shell environment.

start (command) Shell command

In computing, start is a command of the IBM OS/2, Microsoft Windows and ReactOS command-line interpreter cmd.exe to start programs or batch files or to open files or directories using the default program. start is not available as a standalone program. The underlying Win32 API is ShellExecute.

Command-line interface Type of computer interface based on entering text commands and viewing text output

A command-line interface (CLI) processes commands to a computer program in the form of lines of text. The program which handles the interface is called a command-line interpreter or command-line processor. Operating systems implement a command-line interface in a shell for interactive access to operating system functions or services. Such access was primarily provided to users by computer terminals starting in the mid-1960s, and continued to be used throughout the 1970s and 1980s on VAX/VMS, Unix systems and personal computer systems including DOS, CP/M and Apple DOS.

cat (Unix)

cat is a standard Unix utility that reads files sequentially, writing them to standard output. The name is derived from its function to concatenate files. It was ported to a number of operating systems.

References

  1. "Using "History" to Repeat Commands". University of Washington. Retrieved 25 July 2013.
  2. https://github.com/reactos/reactos/blob/master/base/shell/cmd/history.c
  3. http://wiki.kolibrios.org/wiki/Shell
  4. "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.
  5. Darwin Kernel Version 15.0.0: Sat Sep 19 15:53:46 PDT 2015

Further reading