http://www.lampbrother.net
Linux
基础教程
linux
下学习
history
命令的用法实例
1.
使用
HISTTIMEFORMAT
显示时间戳
当你从命令行执行
history
命令后,
通常只会显示已执行命令的序号和命令本身。
如果你想要查看命
令历史的时间戳,那么可以执行:
复制代码代码如下
:
# export HISTTIMEFORMAT='%F %T '
# history | more
1 2008-08-05 19:02:39 service network restart
2 2008-08-05 19:02:39 exit
3 2008-08-05 19:02:39 id
4 2008-08-05 19:02:39 cat /etc/redhat-release
注意:
这个功能只能用在当
HISTTIMEFORMAT
这个环境变量被设置之后,
之后的那些新执行的
bash
命
令才会被打上正确的时间戳。在此之前的所有命令,都将会显示成设置
HISTTIMEFORMAT
变量的时间。
2.
使用
Ctrl+R
搜索历史
Ctrl+R
是我经常使用的一个快捷键。
此快捷键让你对命令历史进行搜索,
对于想要重复执行某个命令
的时候非常有用。当找到命令后,通常再按回车键就可以执行该命令。如果想对找到的命令进行调整后再
执行,则可以按一下左或右方向键。
复制代码代码如下
:
# [Press Ctrl+R from the command prompt, which will display the reverse-i-search prompt]
(reverse-i-
search)`red‘: cat /etc/redhat
-release
[Note:
Press
enter
when
you
see
your
command,
which
will
execute
the
command
from
the
history]
# cat /etc/redhat-release
Fedora release 9 (Sulphur)
3.
快速重复执行上一条命令