Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.

The history command is used to display the history commands that a user has executed. You can add or delete the history commands. If you use Linux frequently, using the history command is a great way to increase your productivity and make your work more productive.

use

Syntax format

History [option][parameter]Copy the code

Common options:

  • -c: Clears the current history command
  • -a: Writes the commands in the history command buffer to the history command file
  • -r: reads the commands in the history command file into the current history command buffer
  • -w: writes the current history command buffer commands to the history command file

Parameters:

N: Displays the n recent history commands.

The instance

usehistoryCommand Displays the 10 history commands used recently

[root@centos7 ~]# history 10 1086 docker attach my_mysql 1087 pyenv local 3.7.4 1088 ll 1089 CD lnav-0.10.0 1090 ll 1091  cd .. / 1092 cd PyPy/ 1093 ls 1094 vim test.py 1095 history 10Copy the code

Executes a specified command from the command history

In the history command above, if we want to repeat command 1086, we can! 1086 can.

! 1086Copy the code

In the process of use, we usually use it together with grep commands, for example, to query commands containing docker:

history | grep docker
Copy the code

Write the login command to the history file

history -w
Copy the code

Read the contents of the command history file into the current shell’s history memory

history -r  
Copy the code

Appends the current shell session history command to the command history file

history -a  
Copy the code

Clear the current history command list

history -c 
Copy the code

Use HISTIGNORE to ignore specific commands in history

For example, if you don’t want to display simple commands like PWD and ll during history, you can set them as follows:

export HISTIGNORE="pwd:ll:"
Copy the code

Original is not easy, if small partners feel helpful, please click a “like” and then go ~

Finally, thank my girlfriend for her tolerance, understanding and support in work and life!