The history
command in Bash is used to display the list of previously executed commands in the current shell session. It allows users to recall and reuse commands without having to retype them, enhancing productivity and efficiency in the command line.
The basic syntax of the history
command is as follows:
history [options] [arguments]
-c
: Clears the entire history list.-d offset
: Deletes the history entry at the specified offset.-a
: Appends the new history lines to the history file.-r
: Reads the history from the history file and adds it to the current session.-n
: Reads the history lines not already read from the history file.history
history 10
history -c
history -d 5
history -a
history -r
!
operator followed by a command number to quickly execute a previous command (e.g., !100
executes the command listed as number 100 in your history).history
with grep
to search for specific commands in your history, like this:
history | grep "git"