Linux view history command execution record history

Every time we type a linux command, sometimes we want to use the command we have used before. Normally, we will press the ↑↓ arrow to find the historical command record. Then if I want to use a command that was executed 1 day ago, Do you have to press ↑100 times? It is unrealistic to show this, we can use the history command
In the actual process, history is still very useful

View historical command execution records (history)

history

View the historical execution record of the tail command

history | grep tail

In the execution history, the order number is 1000

Execute the last command (enter two exclamation marks directly)

!!

Find the last 5 history records (two ways)

history 5
history | tail -5

Clear history

history -c

Write all current history records to the history file, by default it is written to ~/.bash_history

history -w
cat ~/.bash_history

Leave a Reply