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.
- With no options, display the command history list with line numbers.
- Lines listed with a * have been modified.
history [n] history -c history -d offset history -anrw [filename] history -p arg [arg ...] history -s arg [arg ...]
- n will list only the last n lines.
- filename is used as the name of the history file; if not, the value of HISTFILE is used.
- -c: Clear the history list by deleting all the entries.
- -d Offset delete the history entry at position offset.
- -a Append the new history lines (history lines entered since the beginning of the current bash session) to the history file.
- -n Read the history lines not already read from the history file into the current history list. These are lines appended to the history file since the beginning of the current bash session.
- -r Read the contents of the history file and use them as the current history.
- -w Write the current history to the history file, overwriting the history file’s contents.
- -p Perform history substitution on the following args and display the result on the standard output. Does not store the results in the history list. Each arg must be quoted to disable normal history expansion.
- -s Store the args in the history list as a single entry. The last command in the history list is removed before the args are added.
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.
A colon-separated list of patterns used to decide which commands should be saved on the history list.
Characters controlling history expansion and quick substitution.
- The first character is the history substitution character, usually !.
- The second is the quick substitution character, usually ^.
- The third is the history comment character, usually #.
The value of the history file
Reading the history: One line by one line
- Up/Down Arrows
Executing an command in the history with its id
The first number of the history output is the history id
!historyId # mutliple !historyId1; !historyId2;
Lets you search your command history for a search term.
Steps to search commands that included the search term 'youpi':
- Hit Ctrl+R and type 'youpi'.
- You will get the last command
- If this is not what you want, type Ctrl + R
- When the desired command appears, uses :
- the left arrow to select it.
- or Enter to execute it
history | grep mySearchTerm