Table of Contents

Bash - History (builtin command)

About

history is a Builtin Command that shows the history of the command executed.

Management

Don't add a command in the history

A space at the start of a command will stop the command (and any password) from being stored in the history.

Syntax

history [n]
history -c
history -d offset
history -anrw [filename]
history -p arg [arg ...]
history -s arg [arg ...]

where:

Configuration

HISTTIMEFORMAT

If the shell variable HISTTIMEFORMAT is set and not null, it is used as a format string for strftime to display the time stamp associated with each displayed history entry.

The time stamp information associated with each history entry is written to the history file.

export HISTTIMEFORMAT="%d/%m/%y %T 

No intervening blank is printed between the formatted time stamp and the history line.

HISTIGNORE

A colon-separated list of patterns used to decide which commands should be saved on the history list.

histchars

Characters controlling history expansion and quick substitution.

HISTFILE

The value of the history file

Shortcut

All shortcuts can be found with the bind command

bind -P | grep history
beginning-of-history can be found on "\e<", "\e[5~".
dynamic-complete-history can be found on "\e\C-i".
end-of-history can be found on "\e>", "\e[6~".
forward-search-history can be found on "\C-s".
history-and-alias-expand-line is not bound to any keys
history-expand-line can be found on "\e^".
history-search-backward is not bound to any keys
history-search-forward is not bound to any keys
next-history can be found on "\C-n", "\eOB", "\e[B".
non-incremental-forward-search-history can be found on "\en".
non-incremental-forward-search-history-again is not bound to any keys
non-incremental-reverse-search-history can be found on "\ep".
non-incremental-reverse-search-history-again is not bound to any keys
previous-history can be found on "\C-p", "\eOA", "\e[A".
reverse-search-history can be found on "\C-r".
vi-fetch-history is not bound to any keys

Reading the history: One line by one line

Executing an command in the history with its id

The first number of the history output is the history id

!historyId
#  mutliple
!historyId1; !historyId2;

Ctrl+R

Lets you search your command history for a search term.

Steps to search commands that included the search term 'youpi':

Grep

history | grep mySearchTerm

Documentation / Reference