Linux Command History detailed

Source: Internet
Author: User


Concept: As the name implies, the commands we have lost on the Linux terminal will be loaded into memory so that we can quickly invoke the command. In addition, Bash has the ability to automatically record command history, and commands executed by the user are automatically logged to the. bash_history hidden file in their home directory when logging off, so that we can understand the user's entire operation of the system and query for possible causes of errors.

How to view the command history:

    1. You can view the files by opening them directly


Command

[email protected] ~]$ cat. bash_history

2. Scroll up or down the history via the keyboard's up and down keys

3. View history with the historical command

Command history:

Command history-Related settings:

echo $HISTSIZE View the size of the variable history command (how many commands are cached) the size of the command history is 1000 by default.

echo $HISTFILESIZE command history file Size (how many history commands can be saved by the command history file)

Echo $HISTTIMEFORMAT (show command execution time)

echo $HISTFILE command history file (/root/.bash_history user's path)

Echo $HISTCONTROL See how your history is saved:

Ignoredups does not record the following repeated commands (only sequential Repeat commands are logged once)

Ignorespace does not log commands that start with a blank

Ignoreboth does not log commands that begin with whitespace, and successive repeats of commands are recorded only once

How to: Modify the command history size in the cache

First step: Echo "histsize=10" >>/etc/profile (load variable into file)

Step Two: Source/etc/profile (load Cache)

Step Three: Vim/etc/profile (see if you are adding to a file)

Fourth Step: History (View command historical size)

[[email protected] ~]# echo "histsize=10" >>/etc/profile[[email protected] ~]# Vim/etc/profile[[email protected] ~  ]# source/etc/profile [[email protected] ~]# history 257 as 258 FAS 259 AFS 260 af 261 a 262 fhsitory 263 History of Vim/etc/profile 265 source/etc/profile 266 History



The following environment variables can be modified in accordance with the above method to view the results of the execution


Histroy View command History

-C Empty Command history

-D Delete the specified hsitory record, which can be added in the following section

-a append, Save the History command (append the new command in the cache to the history file)

-W saves the cached memory in the history file (replaces the command history disk)

history-d 500 Delete the No. 500 row record, move up the back

History-d 500 10 Delete line No. 500 start, next 10 lines

Tips for using historical commands:

Executive 100th!n-------! 100

!-n what is the countdown to the execution of the command history?

!! Perform previous history

!man Executes the most recent command with the start of the execution string

!$ Apply the last parameter of the previous command

!^ apply the first parameter of the previous command

ESC Press to release and press. You can display the previous command

A few common configuration files:

Command history file Configuration/etc/profile: Global valid/.bash_profile: Current user valid

Command History Cache Configuration/ETC/BASHRC: Global active/.bash_history: Current user valid

Summarize the method of repeating the last command:!!,!-1, ctrl+p, press the key

Note the point:

After executing the command, the system automatically loads the command into the cache, and when it exits the shell and loads into the/.bah_history login shell, the command history/.bash_history is automatically read.


This article is from the "14545" blog, please be sure to keep this source http://10793128.blog.51cto.com/10783128/1832359

Linux Command History detailed

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.