跳转至

history 命令


2015-02-06 by dongnan

举个栗子

清除历史命令记录

history -c

不过最近发现对于 XenServer 创建的Linux 虚拟机,即使清除历史记录,重启系统后还会有历史记录,可以使用下面命令清理。

禁用历史记录

其实就是将HISTSIZE环境变量设置为0,这样所有的指令都不会记录下来了,退出 shell 登陆恢复。

export HISTSIZE=0
history

# 输出为空

定义History时间

设置环境变量(临时)

export HISTTIMEFORMAT="%F %T "

history 命令返回结果带有时间:

history | tail -n2

2014-03-22 14:47:25 export HISTTIMEFORMAT="%F %T "
2014-03-22 14:47:26 history | tail -n2

也可以编辑 .bashrc 文件,添加 HISTTIMEFORMAT 变量。

命令帮助

history --help
history: history [-c] [-d offset] [n] or history -anrw [filename] or history -ps arg [arg...]
    Display or manipulate the history list.

    Display the history list with line numbers, prefixing each modified
    entry with a `*'.  An argument of N lists only the last N entries.

    Options:
      -c    clear the history list by deleting all of the entries
      -d offset delete the history entry at position OFFSET. Negative
            offsets count back from the end of the history list

      -a    append history lines from this session to the history file
      -n    read all history lines not already read from the history file
            and append them to the history list
      -r    read the history file and append the contents to the history
            list
      -w    write the current history to the history file

      -p    perform history expansion on each ARG and display the result
            without storing it in the history list
      -s    append the ARGs to the history list as a single entry

    If FILENAME is given, it is used as the history file.  Otherwise,
    if HISTFILE has a value, that is used, else ~/.bash_history.



回到页面顶部