Brief
Again to knock that long to have no friend's order, really no longer love ...
With the history of this order I think we can love again!
>history
Syntax: History [n |-c |-raw Histfile]
n--number that represents the most recent N-pen command
-c--means clearing everything in history (essentially cleaning up the content saved in $histfile)
-a--means to save the current session from the last execution of the history-a histfile command after all commands are saved to the Hisfile file, if the Histfile default value is the file pointed to by the $histfile variable (~/.bash_history)
-r--represents the history of reading content from Histfile to the current session
-w--indicates that the current hitory content is written to Histfile
How 2 execute the command show by ' history '
M1. !n
N is a number that represents the command that executes the specified number in the history
M2. !cmd
CMD is a partial string of commands, starting with the most recent to match the first command at the beginning of the string and executing
M3. !! or -1 or Ctrl + P
! and-1 means get the most recent command and execute. (Ctrl + p for shortcut keys)
M4. !? string? or Ctrl + R
String is a part of the command string. Matches the first command containing the string from the nearest start and executes (Ctrl + R is quick)
M5. FC N
N is a number that represents the command that executes the specified number in the history. However, a text editor opens and displays the command, and we can modify the command and then exit the editor to execute the modified command.
M6. ^replacedstring^newstring or !:s/replacedstring/newstring
Executes a new command after replacing the replacedstring content of the previous command with the newstring content
> ps-ef| grep httpd> ^httpd^grep
M7. !! &
Execute another command after executing the previous command
Fetch Args from the history commnad
!^ Gets the first parameter of the previous command.
!$ Gets the last parameter of the previous command.
!:n Gets the nth parameter of the previous command, and N starts at 1. (The command name is selected at 0)
!:n-x Gets the nth parameter of the previous command to the x parameter, and both N and x start at 1. (The command name is selected at 0)
!* gets all the arguments for the previous command.
!n* N is a number that gets all the arguments from the nth parameter (with the nth parameter) of the previous command.
!n- N is a number that gets all parameters except the last argument from the nth parameter (with the nth parameter) of the previous command.
Configurations begin with "HIST"
Histtimeformat
The output format used to set the history command.
>export histtimeformat='%F%T'
histsize
The total number of entries used to control the command history. (Disables the command history feature when set to 0)
>export histsize=0
Histfile
Used to set the save location for the command history, which is saved in the ~/.bash_history file by default.
>export histfile=~/.cmd_history
Histcontro L
Reject successive repeats of a command history entry: >export histcontrol=ignoredups
Clean up all duplicate command history entries: >export histcontrol=erasedups
Records that begin with a space are not logged: >export histcontrol=ignorespace
Histignore
Used to set some commands that will not be saved to the history
>export histignore='pwd:ls:ls-ltr:'
The above representations Pwd,ls and ls-ltr will not be saved.
Note: The above environment variables are only valid for the current session and will expire when the session exits. For all sessions to be valid, you need to write the settings to the ~/.bash_profile file.
Conclusion
With Man 3 We can learn more about the cool gameplay of history!
Respect the original, reprint please indicate from: http://www.cnblogs.com/fsjohnhuang/p/4753904.html ^_^ Fat Boy John
Thanks
Http://blog.sina.com.cn/s/blog_5caa94a00100gyls.html
http://blog.csdn.net/yorkingalan/article/details/7166583
Bash Magic Hall: An explanation of history usage