Linux history command shows how to use historical instruction records

Source: Internet
Author: User
Tags add numbers

Linux history command shows how to use historical instruction records

The history command is used primarily to display historical instruction records and to release instructions in the history record.
1>history Command Syntax
[[Email protected]]# history [n]
[Email protected]]# history [-c]
[Email protected]]# history [-raw] Histfiles
Parameters:
N: number, to list the most recent n-pen commands
-C: Eliminate all history content in the current shell
-A: Add the current New History command to Histfiles, without adding histfiles,
The default write ~/.bash_history
-r: Read Histfiles's contents into the current Shell's history memory
-W: Writes current history memory content to Histfiles
Linux system when you enter and execute commands in the shell (console), the shell automatically logs your commands to the history list, which is typically saved in the. bash_history file in the user directory. Save 1000 By default, and you can change this value.
If you type history, it will show you the top 1000 historical commands you used, and give them a number, and you'll see a numbered list quickly rolled over the screen. You may not need to see all the items in the 1000 commands, but you can also add numbers to list the most recent n-pen commands.
The history command in Linux not only allows us to query historical commands. We can also use the relevant features to help us execute commands.
2> Run a specific history command
History lists all the historical commands that bash has saved and gives them numbers, and we can run specific historical commands in the same way as the exclamation mark number.
Syntax Description:
[Email protected]]# [!number] [!command] [!]

parameter Description
Number: The meaning of the first instruction;
Command: The first few letters of the instruction
! : The meaning of the previous instruction!
3>history Command Combat
List all the history records:
[[email protected]] # History
Only the last 10 records are listed:
[[email protected]] # History 10 (note, history and 10 have spaces in between)
Execute the command using the command record number, and execute the 99th command in the history list
[[email protected]] #!99 (! And 99 no spaces in the middle)
Repeat the previous command
[[email protected]] #!!
Execute the last command that starts with RPM (!?). is a string, which can be lost randomly, the shell will search forward from the last history command, and the first matching command will be executed. )
[[email protected]] #!rpm
List all history on a per-screen basis:
[[Email protected]]# History | More
Immediately clears the history of all current historical commands
[[email protected]] #history-C
In addition to using the history command, you can also use the UP and DOWN ARROW keys to scroll through the command past in the shell or GUI terminal prompts, until you find the command you want. This allows us to easily edit one of the preceding commands without having to enter similar commands repeatedly.
The use of the history command is really great! But you need to be careful about security! Especially the root history file, this is the hacker's favorite! Because the careless root will be a lot of important information in the process of execution will be recorded in the ~/.bash_history, if the file is parsed, the consequences are unimaginable!

Linux history command shows how to use historical instruction records

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.