How to use the history command in linux to display historical Command Records

Source: Internet
Author: User
In linux, the history Command displays historical Command Records. The History Command is mainly used to display historical Command Records and issue commands in historical records. 1 & gt; History command syntax: [test @ linux] # history [n] [test @ linux] # history [-c] [test @ linux]... in linux, the history Command displays historical Command Records. The History Command is mainly used to display historical Command Records and issue commands in historical records. 1> History command syntax: [test @ linux] # history [n] [test @ linux] # history [-c] [test @ linux] # history [-raw] histfiles parameter: n: number, to list the latest n commands-c: remove all the history contents in the current shell-a: add the newly added history commands to histfiles. If no histfiles is added, write by default ~ /. Bash_history-r: read the contents of histfiles to the current shell's history memory-w: write the current history memory into the histfiles Linux system when you are in shell (console) when you enter and execute the command, shell will automatically record your command to the history list, which is generally stored in the user directory. bash_history file. By default, 1000 entries are saved. you can change this value. If you type history, history will show you the first 1000 historical commands you are using and mark them, you will see a list of numbers quickly rolled out from the screen. You may not need to view all the projects in the 1000 commands. you can also add a number to list the latest n commands. In linux, the history command not only allows us to query historical commands, but also allows us to execute commands using related functions. 2> running a specific historical command, history, lists all history commands saved by bash, and signs them. we can run specific historical commands in the "exclamation mark" method. syntax description: [test @ linux] # [! Number] [! Command] [!] Parameter description: number: the meaning of the instruction; command: the first letter of the instruction!: The meaning of the previous command! 3> The History command lists all historical records in practice: [test @ linux] # history only lists the last 10 records: [test @ linux] # history 10 (note, there are spaces between history and 10) use the command record number to execute the command, and execute the 99th command in the history list [test @ linux] #! 99 (! There is no space in between and 99) repeat the previous command [test @ linux] #! Run the last command starting with rpm (!?? It indicates a String, which can be input at will. Shell searches forward from the last historical command, and the first matched command will be executed .) [Test @ linux] #! Rpm displays all historical records on screen: [test @ linux] # history | more immediately clears the records of all historical commands in history [test @ linux] # history-c. Besides using the history Command, at the prompt of shell or GUI terminal, you can also use the up and down arrow keys to read the command history (the down arrow will look forward) until you find the required command. This allows us to easily edit a previous command without having to repeat similar commands. The History command is really useful! But be careful about security issues! Especially the root history file, which is a favorite of hackers! Because the careless root will record a lot of important information during execution ~ /. In bash_history, if this file is parsed, the consequences will be unimaginable!
Related Article

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.