Linux commands: History

Source: Internet
Author: User

Life Introduction to the Order:

The role of the Linux History command is to record commands that have been executed. Usage: History [n] n is a number, listing the most recent n command-C removes all history commands from the current shell to the history [-raw] Histfiles-a writes the currently new command to Histfiles, which is written by default ~/.bash_hi Story-r reads Histfiles content into the current shell's history memory-W writes the current history memory to Histfiles


1. command format:

History [n] n is a number


2. Command function:

1. View the command history

2. Clear the command history

3. Save Command history


3. Command parameters:

-C : Empty command history

- D [n]: Delete a command at the specified location

- W : Save the Command history to the history file


4. usage Examples:


Example one: view the last 10 command history

[[Email protected] default]# history 10
1218 passwd Tom
1219 File Useradd
1220 cd/etc/default/
1221 LL
1222 file Useradd
1223 Cat Useradd
1224 Q
1225 Man
1226 Mans 1 History
1227 History 10



Instance one: use! Execute history command.

1,! Number executes the first few commands

2,! Command executes from the most recent command, with commands beginning with

3,!! Perform the previous article


[Email protected] default]#!1222
File Useradd
Useradd:ascii text


[Email protected] default]#!fil
File Useradd
Useradd:ascii text

< Span style= "Font-family:simsun;" >

[[email protected " default]# < Span style= "Font-family:simsun;" >

File Useradd
Useradd:ascii text


Example Two : History configuration changes

EG1, History record line number

[Email protected] tmp]# echo $HISTSIZE
1000


EG2, default record 1000 line configuration file modified in/etc/profile

[Email protected] tmp]# cat/etc/profile-n

histsize=1000


eg3, historical command files are recorded in ~/.bash_history
To get the history command of Linux to display time, history is defaulted without time, added in/etc/profile

Export histtimeformat= "%y-%m-%d%h:%m:%s"


EG4, view. bash_history

Head ~/.bash_history
example Three:Same account number of simultaneous logins written to history

When you log on to the system with bash, the system reads the previously run commands from ~/.bash_history.

When you log off, update the latest Histsize command to the ~/.bash_history file.

When the same account is logged in to more than one bash at the same time, only the last Exit is written to Bash_history, and the others are overwritten.


History-w is forced to write immediately, keeping only the latest.


example Four:Ctrl+r Reverse Query History command

Use the Ctrl+r reverse query History command to display the latest matching match if you want to continue to query upward, press Ctrl+r


[[Email protected] ~]# History 6
1238 Cat. Bash_history
1239 Rpm-q Bind-lib


(reverse-i-search) 'rpm': rpm-q bind-lib <<== ctrl+r after input rpm




Linux commands: History

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.