Linux History Command And Examples

NAME
history – GNU History Library

COPYRIGHT
The GNU History Library is Copyright (C) 1989-2011 by the Free Software Foundation, Inc.

DESCRIPTION
Many programs read input from the user a line at a time. The GNU History library is able to keep track of those lines, associate arbitrary data with each line, and utilize information from previous lines in composing new ones.

HISTORY EXPANSION
The history library supports a history expansion feature that is identical to the history expansion in bash. This section describes what syntax features are available.

History expansions introduce words from the history list into the input stream, making it easy to repeat commands, insert the arguments to a previous command into the current input line, or fix errors in previous commands quickly.

History expansion is usually performed immediately after a complete line is read. It takes place in two parts. The first is to determine which line from the history list to use during substitution. The second is to select portions of that line for inclusion into the current one. The line selected from the history is the event, and the portions of that line that are acted upon are words. Various modifiers are available to manipulate the selected words. The line is broken into words in the same fashion as bash does when reading input, so that several words that would otherwise be separated are considered one word when surrounded by quotes (see the description of history_tokenize() below). History expansions are introduced by the appearance of the history expansion character, which is ! by default. Only backslash (\) and single quotes can quote the history expansion character.

Event Designators
An event designator is a reference to a command line entry in the history list. Unless the reference is absolute, events are relative to the current position in the history list.

! Start a history substitution, except when followed by a blank, newline, = or (.
!n Refer to command line n.
!-n Refer to the current command minus n.
!! Refer to the previous command. This is a synonym for `!-1′.
!string
Refer to the most recent command preceding the current position in the history list starting with string.
!?string[?]
Refer to the most recent command preceding the current position in the history list containing string. The trailing ? may be omitted if string is followed immediately by a newline.
^string1^string2^
Quick substitution. Repeat the last command, replacing string1 with string2. Equivalent to “!!:s/string1/string2/” (see Modifiers below).
!# The entire command line typed so far.

History Syntax

history [-c] [-d offset] [n]

or

 history -anrw [filename]

or

 history -ps arg [arg...]

Display or manipulate the history list.

Display the history list with line numbers, prefixing each modified
entry with a `*’. An argument of N lists only the last N entries.

History Options

-c clear the history list by deleting all of the entries
-d offset delete the history entry at offset OFFSET.

-a append history lines from this session to the history file
-n read all history lines not already read from the history file
-r read the history file and append the contents to the history
list
-w write the current history to the history file
and append them to the history list

-p perform history expansion on each ARG and display the result
without storing it in the history list
-s append the ARGs to the history list as a single entry

If FILENAME is given, it is used as the history file. Otherwise,
if $HISTFILE has a value, that is used, else ~/.bash_history.

If the $HISTTIMEFORMAT variable is set and not null, its value is used
as a format string for strftime(3) to print the time stamp associated
with each displayed history entry. No time stamps are printed otherwise.

Exit Status:
Returns success unless an invalid option is given or an error occurs.

You might also like:

Sidebar



back to top