The history command of Linux uses Daquan

Source: Internet
Author: User

History command

History Command: used to display historical records and executed command commands. The history command reads the directory from the historical command file into the history command buffer and writes the directory in the history command buffer to the command file. When this command is used alone, only the history command is displayed, and on the command line, you can use the symbol ! to execute the history command of the specified ordinal . For example , to perform a 2nd history command, enter !2 .

The history command: is stored in memory and is automatically saved or read when you exit or log in to the shell. In memory, the history command can only store 1000 historical commands, which are controlled by environment variables HISTSIZE . The default is to not show the execution time of the command, the execution time of the command, history has been recorded, just not shown .

Grammar:
History (options) (parameters)
Options:
   -n:    Displays the last N records in the history;   -    C:   empties the current History command;   -     A:   Writes the command in the history command buffer to the history command file;   -    r:   reads commands from the history command file into the current History command buffer;   -    W:   Writes the current History command buffer command to the history command file;  -d<offset>   :  Delete the first offset command in the history  -n<filename>:  reading the specified file  
Parameters:
N: Prints the most recent n history command.
Instance:
# view historical execution Records [Ljs@vm ~]$ [ljs@vm# view history execution record
  #查看历史执行记录后 5 lines  [Ljs  @vm  ~]$ [Ljs   @vm  ~]$ history   5   #   View 5 records after history execution   
#   ! Number executes the first few commands [Ljs@vm ~]$ [ljs@vm ~]$! Ten #  !! Executes the previous [Ljs@vm ~]$ [ljs@vm#  executes the previous command
 Show Execution History time:
1, by default, history does not record the execution time of the command, it is difficult to analyze. We can use Histtimeformat to show timestamp in history.
2, put the above export histtimeformat= "%F%T" commands are added to the ~/.BASHRC to automatically open the history timestamp after logging in. After the add is complete, execute the source. BASHRC to make it effective. Valid for current account only.
3, in fact, the Histtimeformat format is the format of the Strftime function, such as the above "%F%T", the% F indicates the date of the y-m-d format,%T indicates that the time of the format is shown h-m-s.
4, use ctrl+r search History command;after you have executed a fairly long list of commands, you can simply search through the history command with the keyword and re-execute the command without having to lose the whole command again. To do this: press ctrl+r and enter the keyword. If you search for "date", the command that displays history has the command "date" in the date "+ today is:%f,%a, time is:%T. Ready to eat." Press ENTER, you can re-execute this command, and press the left ARROW key or the RIGHT ARROW key can be directly modified, after changing the press ENTER to execute, very convenient!
Note: when you press ctrl+r at the command prompt, the terminal will display the following prompt Reverse-i-search "
# Configure the HISTTIMEFORMAT environment variable to add a timestamp to the history record [Ljs@vm ~]$ [ljs@vm ~]$ export histtimeformat="" # Configure the HISTTIMEFORMAT environment variable to add a timestamp to the history record

The history command of Linux uses Daquan

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.