Linux命令:history

显示历史(执行过的)命令。

history [n]

history -c

history -d offset

history -anrw [filename]

history -p arg [arg ...]

history -s arg [arg ...]

不带任何参数显示所有执行过的命令。一个命令一行,每行前有行号。带*,表示曾被修改过。

n   ,显示最后(最近)执行的n命令。

-c ,清空所有历史命令。

-w,把缓存中的命令写入历史命令保存文件~/.bash_history

历史命名文件bash_history中保存的与终端上history列出的并不完全相同。

history列出的不仅有文件中的,还有本次登录后执行的命令。需要正确注销后才会写入文件
bash_history文件中保存的只有上一次正确注销后的命令。

配置文件/etc/profile

HISTSIZE ,默认保存1k条,可以在环境变量配置文件/etc/profile中修改 HISTSIZE=xxx
HISTFILE,默认保存文件修改 HISTFILE=/path/FILENAME。 默认为~/.bash_history。
HISTCONTROL,剔除连续重复的条目 HISTCONTROL=ignoredups
HISTIGNORE,忽略指定命令HISTIGNORE=”pwd:ls:cd:”
HISTTIMEFORMAT,格式化输出HISTTIMEFORMAT=’%F %T ’ ,bt只能输出设置生效之后的

调用历史命令

Ctrl+R  直接键入想要查询的命令,进行动态模糊查询:直接回车可以执行

使用上下箭头调用以前的历史命令
使用 !n 重复执行第n条历史命令
使用 !! , !-1 重复执行上一条命令

Ctrl+p ,调取上一条命令。
使用 !str 重复执行最后一条以str开头的命令

帮助

man history

 1        history [n]
 2        history -c
 3        history -d offset
 4        history -anrw [filename]
 5        history -p arg [arg ...]
 6        history -s arg [arg ...]
 7               With no options, display the command history list with line numbers.  Lines listed with a * have been modified.  An argument of n lists only the last n lines.  If  the
 8               shell  variable  HISTTIMEFORMAT  is  set  and  not null, it is used as a format string for strftime(3) to display the time stamp associated with each displayed history
 9               entry.  No intervening blank is printed between the formatted time stamp and the history line.  If filename is supplied, it is used as the name of the history file; if
10               not, the value of HISTFILE is used.  Options, if supplied, have the following meanings:
11               -c     Clear the history list by deleting all the entries.
12               -d offset
13                      Delete the history entry at position offset.
14               -a     Append the ``new‘‘ history lines (history lines entered since the beginning of the current bash session) to the history file.
15               -n     Read  the  history lines not already read from the history file into the current history list.  These are lines appended to the history file since the beginning
16                      of the current bash session.
17               -r     Read the contents of the history file and use them as the current history.
18               -w     Write the current history to the history file, overwriting the history file‘s contents.
19               -p     Perform history substitution on the following args and display the result on the standard output.  Does not store the results in the  history  list.   Each  arg
20                      must be quoted to disable normal history expansion.
21               -s     Store the args in the history list as a single entry.  The last command in the history list is removed before the args are added.
22
23               If  the  HISTTIMEFORMAT  variable is set, the time stamp information associated with each history entry is written to the history file, marked with the history comment
24               character.  When the history file is read, lines beginning with the history comment character followed immediately by a digit are interpreted  as  timestamps  for  the
25               previous  history line.  The return value is 0 unless an invalid option is encountered, an error occurs while reading or writing the history file, an invalid offset is
26               supplied as an argument to -d, or the history expansion supplied as an argument to -p fails.

举例

history

显示历史命令列表,按执行的先后顺序从上到下显示。

原文地址:https://www.cnblogs.com/ChinaGo/p/10609855.html

时间: 2024-08-01 16:47:28

Linux命令:history的相关文章

Linux 命令 - history: 显示或操作历史列表

命令格式 history [-c] [-d offset] [n] history -anrw [filename] history -ps arg [arg...] 命令参数 -c 清除历史列表. -d offset 删除编号为 offset 的历史条目. n 显示最近的 n 条记录. 历史记录扩展 序列 行为  !!  重复最后一个执行过的命令.按向上箭头键再按 Enter 键也可以实现相同的功能,而且更符合操作习惯.  !number   重复历史记录中第 number 行的命令.  !s

每天学习Linux命令——history

history命令的功能是显示使用过的命令,并为其编号.下面几条命令是history的不同操作: history n 显示最近使用过的n条命令. history -c 将当前shell中历史清空. history -d 801 删除编号为801的命令. history -a 追加最新一条命令到历史文件中. history -n 显示还没有从历史文件中读取的历史记录. history -r 将历史文件中的记录作为当前shell的历史记录. history -w 将当前记录写入历史文件中,覆盖原内容

Linux命令:history

history命令简介: linux的history命令的作用是,记录执行过的命令. 用法: history [n] n为数字,列出最近的n条命令 -c 将目前shell中的所有history命令消除 history [-raw] histfiles -a 将目前新增的命令写入histfiles, 默认写入~/.bash_history -r 将histfiles内容读入到目前shell的history记忆中 -w 将目前history记忆的内容写入到histfiles 1.命令格式: hist

Linux中history历史命令使用方法详解

在/etc/profile里添加如下: #History export HISTTIMEFORMAT="[%F %T]" HISTDIR=/home/common/.hist if [ ! -d $HISTDIR ]; then         mkdir -p $HISTDIR         chmod 777 $HISTDIR fi export HISTSIZE=100000 export HISTFILE="$HISTDIR/${LOGNAME}.hist"

Linux系统history命令显示日期和时间,增加history命令保留个数

编辑 /etc/profile文件 # vi /etc/profile 在文件末尾添加 export HISTTIMEFORMAT='%F %T '     #注意有个空格,为了显示时日期与命令之间有空格分割. export HISTSIZE="10000"    #默认保留1000条. 保存 重新login即可生效. Linux系统history命令显示日期和时间,增加history命令保留个数

Linux下history命令详解---转载

Linux下History命令主要用于显示历史指令记录内容, 下达历史纪录中的指令 . >History命令语法:[[email protected]]# history [n][[email protected]]# history [-c][[email protected]]# history [-raw] histfiles 参数:n  :数字,要列出最近的 n 笔命令列表-c :将目前的shell中的所有 history 内容全部消除-a :将目前新增的history 指令新增入 hi

linux通过history查看命令执行时间

Linux的bash内部命令history就可以显示命令行的命令历史,默认环境执行 history 命令后,通常只会显示已执行命令的序号和命令本身.如果想要查看命令历史的时间戳,那么可以执行:# export HISTTIMEFORMAT='%F %T '# history | less1 2008-08-05 19:02:39 service network restart2 2008-08-05 19:02:39 exit3 2008-08-05 19:02:39 id

Linux下history命令用法

如果你经常使用 Linux 命令行,那么使用 history(历史)命令可以有效地提升你的效率.本文将通过实例的方式向你介绍 history 命令的 15 个用法. 使用 HISTTIMEFORMAT 显示时间戳 当你从命令行执行 history 命令后,通常只会显示已执行命令的序号和命令本身.如果你想要查看命令历史的时间戳,那么可以执行:# export HISTTIMEFORMAT='%F %T '# history | more1 2008-08-05 19:02:39 service n

linux下history命令显示历史指令记录的使用方法

linux下history命令显示历史指令记录的使用方法 History命令主要用于显示历史指令记录内容, 下达历史纪录中的指令 .1>History命令语法: [[email protected]]# history [n][[email protected]]# history [-c][[email protected]]# history [-raw] histfiles参数:n   :数字,要列出最近的 n 笔命令列表-c  :将目前的shell中的所有 history 内容全部消除-