linux - history command

| --linux - history command
  to display history and instruction executed commands
  history command: is stored in memory when you exit or log shell, automatically save or read.
  In memory, history command only capable of storing 1000 history command, this number is controlled by the environment variable HISTSIZE.
  The default is not to show the execution time of the command, the command execution time, history has been recorded, but not displayed.
  Home directory command .bash_history documentation and historical information used by the user

  syntax:
    History (Option) (parameters)
  Options:
    -N: display recent history of N records;
    -c: Clear the current command history;
    -a: the history command buffer write command history command file;
    -r: the history command file command reads the current history command buffer;
    -w: the current command history command buffer write command history file;
    - d <offset>: delete the history of the offset command
    -n <filename>: reads the specified file
  parameters:
    n: n recent print commands.

| - using the history command specified index!.
! number execute first few commands
! command from the command found in the most recent command beginning with the command to perform
an execution on !!

| - customize history function

  Syntax: NAME = 'VALUE'

    HISTSIZE: the number of lines recorded history

    HISTFILE: history log file directory

    HISTFILESIZE: history log file directory rows
  variable write / etc / profile or in files under /etc/profile.d
  or write files in the home directory .proflie
eg:
  View the number of rows history records
    echo $ HISTSIZE
  modification history record configuration
    HISTSIZE = 1000
    Export HISTSIZE
    or
    export HISTSIZE = 1000

shows the execution history recording time
  1, default execution time of the case, history does not record command, it is difficult to analyze them.
    We can use HISTTIMEFORMAT display TIMESTAMP (time stamp) in history.
  2, the above export HISTTIMEFORMAT = "% F% T " is added to the command in ~ / .bashrc
    to automatically open after the timestamp history log. After completion of the addition,
    the implementation of source .bashrc allowed to take effect. Valid only for the current account.
  3, in fact, the format is the format HISTTIMEFORMAT strftime function, such as the above "F.%% T",
    % represents F. YMD shows the date format,% T denotes a time display format such HMS.

eg:
 编辑/etc/profile或在/etc/profile.d下新建*.sh文件。

    vim /etc/profile.d/shit.sh输入下面两行
       HISTTIMEFORMAT="%Y%m%d-%H%M%S "
      或者 HISTTIMEFORMAT="%Y%m%d %T "
      或者 HISTTIMEFORMAT="%F %T "

         export HISTTIMEFORMAT
      或者一行搞定
        export HISTTIMEFORMAT="%y-%m-%d %H:%M:%S "

Guess you like

Origin www.cnblogs.com/xuzhaoping/p/11080613.html