Linux history command history

Source: Internet
Author: User

Linux history command history
1. The role of history in linux is to record the commands that have been executed. Usage: history [n] n is a number, list the latest n commands-c. Delete All history commands in the Current shell by using history [-raw] histfiles-a. Write the newly added commands to histfiles by default ~ /. Bash_history-r reads the histfiles content into the current shell history Memory-w writes the content in the Current history Memory to histfiles

shell > history   34  14-10-28 16:19:24 ll   35  14-10-28 16:19:26 vim test   36  14-10-28 16:19:33 ll   37  14-10-28 16:19:34 ll
Show 3 rows
shell > history 3 1032  14-11-02 16:10:41 history 1033  14-11-02 16:10:46 history |more 1034  14-11-02 16:11:15 history 3
Use! Execute History commands. ! Number! Command from the latest command to find the command that starts with command to execute !! Run the previous
shell > !1046history 3 1045  14-11-02 16:22:38 head ~/.bash_history  1046  14-11-02 16:35:37 history 3 1047  14-11-02 16:35:48 history 3shell > !!history 3 1046  14-11-02 16:35:37 history 3 1047  14-11-02 16:35:48 history 3 1048  14-11-02 16:35:52 history 3shell > !headhead ~/.bash_history #1414484377cd update/#1414484377
2. modify the number of lines in the history record in the history configuration.
shell > echo $HISTSIZE1000shell > 
By default, the configuration file of Line 1 is modified in/etc/profile.
HISTSIZE=1000export  HISTSIZE
The history command file is recorded in ~ /. Bash_history
To display the time of linux's history command, history does not contain time by default, and is added to/etc/profile.
export HISTTIMEFORMAT="%y-%m-%d %H:%M:%S "
View. bash_history
shell > head ~/.bash_history #1414484377cd update/#1414484377ll#1414484388vim address #1414484439ll#1414484440llshell > 
3. When a user logs on to the system using bash and writes it to history multiple times at the same time ~ /. Bash_history read the previously run command. When logging out, update the latest 1000 (HISTSIZE) command ~ /. Bash_history file. You can also use history-w to forcibly write data immediately. Only the latest data is retained.
When you log on to multiple bash instances under the same account at the same time, only the last exit will be written to bash_history, and all others will be overwritten.
4. Run Ctrl + r reverse query history command to display the latest matching record. If you want to continue the upstream query, press Ctrl + r
shell > history 3                                        1048  14-11-02 16:35:52 history 3 1049  14-11-02 16:36:11 head ~/.bash_history  1050  14-11-02 16:41:05 history 3(reverse-i-search)`his': head ~/.bash_history 
Address: http://blog.csdn.net/yonggang7/article/details/40710623

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.