1, history command syntax:
[Test @linux]# History [n]
[test@linux]# history [-c]
[test@linux]# history [-raw] history file
Parameters:
N: Numbers, list the latest n commands.
-c: Erase all historical content in the current shell.
-a: Add the currently added history command to the history file; If the history file is not added,
Write ~/. The default is bash_history.
-r: read the contents of histfiles into the historical memory of the current shell.
-w: Write the current historical memory into histfiles.
When Linux system inputs and executes commands in the shell (console), the shell will automatically record the commands in the history list, which is generally saved in. Bash_history file in the user directory. By default, 1000 entries are saved, or the value can be changed.
If you type history, history will display the first 1000 historical commands used and number them, and you will see a numbered list scrolling quickly on the screen. You may not need to see all the items in 1000 commands, but you can also add numbers to list the latest n commands.
Historical commands in linux can not only query historical commands, but also use related functions to help execute them.
2. Run a specific historical command
History lists all the historical commands saved by bash and numbers them. You can run specific historical commands by "exclamation mark followed by number".
Syntax description:
[test@linux]# [! No.] [! Command] [! ! ]
Parameter description:
Number: the meaning of the first instruction;
Command: The first few letters of a command.
! The meaning of the last instruction!
3. History directs actual combat
List all history:
[Test @linux] # History
Only the latest 10 records are listed:
[test@linux] # history 10 (note that there is a space 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 (! And 99).
Repeat the last command.
[test@linux] #! !
Execute the last one at rpm (! Idspnonenote). ? ? Represents a string, which can be entered arbitrarily. The Shell will search forward from the last historical command, and the first matching command will be executed. )
[test@linux] #! revolutions per minute
List all history by screen:
[Test @linux]# History | More
Immediately clear the record of all current historical commands in the history.
[test@linux] #history -c
In addition to using the history command, at the prompt of the shell or GUI terminal, you can also use the up and down arrow keys to scroll the command history (the down arrow will scroll forward) until you find the required command. This makes it easy to edit one of the previous commands without having to enter similar commands repeatedly.