How to use Linux under History command

Source: Internet
Author: User
Tags add numbers

The history command is primarily used to display historical instruction record content and to release instructions in the history record.
1>history command syntax:
[test@linux]# history [n]
[Test@linux]# History [-c]
[test@linux]# history [-raw] Histfiles
Parameters:
N: Numbers, to list the most recent n-pen commands
-C: Eliminate all history content in the current shell
-A: Add the current New history directive into the histfiles, if not added Histfiles,
The preset write ~/.bash_history
-r: Read the contents of Histfiles to the history memory of the current shell
-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 stored in the. bash_history file in the user's directory. Save 1000 By default, you can also change this value.
If you type history, history will show you the first 1000 historical commands you've used, and you'll see a numbered list that rolls up quickly from the screen. You may not need to look at all the items in 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 history commands. We can also use the relevant functions to help us execute commands.
2> run a specific history command
History lists all of the history commands that bash saves, and gives them a number, and we can run specific history commands using the exclamation mark number.
Syntax Description:
[test@linux]# [!number] [!command] [!!]
Parameter description:
Number: Meaning of the first few instructions;
Command: The first few letters of the instruction
! : The previous instruction means!
3>history Command Combat
To list all history records:
[Test@linux] # History
Only the last 10 records are listed:
[Test@linux] # History 10 (note, history and 10 with spaces in between)
Use command record number to execute command, execute 99th command in history list
[Test@linux] #!99 (no spaces in the middle of! and 99)
Repeat the previous command
[Test@linux] #!!
Perform the last command that starts with RPM (!? ? Represents a string that can be arbitrarily lost, the shell will search forward from the last historical command, and the first matching command will be executed. )
[Test@linux] #!rpm
List all history by screen:
[Test@linux]# History | More
Immediately empty history records of all current history commands
[Test@linux] #history-C
In addition to using the History command, at the shell or GUI terminal prompts, you can also use the UP and DOWN ARROW keys to flip through the command history (the downward arrows will flip through) until you find the desired command. This allows us to easily edit one of the previous commands without having to repeat the same command.
The use of the history command is indeed very large! But you need to be careful about security! In particular, Root's history record file, this is the hacker's favorite! Because careless root will be a lot of important information in the process of execution will be recorded in the ~/.bash_history, if this file is resolved, the consequences of unimaginable!

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.