关于Unix/Linux下查看命令行历史记录(history/.bash_history)

本文介绍了如何通过配置.bash_history来管理Bash的历史命令记录,包括限制历史命令的数量、忽略某些命令、添加时间戳等。此外,还介绍了如何使用history命令进行模糊查询,以及如何利用Control+R快速查找和执行历史命令。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.vi .bash_history

关于.bash_history的配置

export HISTCONTROL=ignoreboth

Don’t save duplicates

export HISTSIZE=10000

这个是针对history命令的设置,The number of commands to remember in the command history. The default value is 500.

export HISTFILESIZE=10000

这个是针对history文件(.bash_history)的设置,The maximum number of lines contained in the history file. When this variable is assigned a value, the his-tory file is truncated, if necessary, by removing the oldest entries, to contain no more than that number of lines. The default value is 500. The history file is also truncated to this size after writing it when an interactive shell exits.
export HISTIGNORE='ls'

A colon-separated list of patterns used to decide which command lines should be saved on the history list.Each pattern is anchored at the beginning of the line and must match the complete line

以上的关于history的说明都可以使用man bash查的到,如果想要让你的配置永久生效,可以把export命令写到.bash_profile或者全局配置文件/etc/profile里

2.history

模糊查询,history | grep -i "xxx"

[oracle@bej301441 ~]$ history | grep -i "FND"
34 2012-07-04 01:29:15 history | grep -i "FND"
35 2012-07-04 01:29:30 FNDLOAD apps/apps 0 Y DOWNLOAD $FND_TOP/patch/115/import/affrmcus.lct PT_CUSTOM_FUC.ldt FND_FORM_CUSTOM_RULES function_name="INV_INVTOMAI"
36 2012-07-04 01:29:33 history | grep -i "FND"
[oracle@bej301441 ~]$

如何让history可以有时间戳显示

# export HISTTIMEFORMAT='%F %T '

....

1027 2012-07-04 01:12:53 ls /etc/bash*
1028 2012-07-04 01:13:17 vi /etc/bashrc
1029 2012-07-04 01:16:04 history
[oracle@bej301441 ~]$

清除history记录

[oracle@bej301441 ~]$ history -c
[oracle@bej301441 ~]$ history
32 2012-07-04 01:20:40 history
[oracle@bej301441 ~]$
注:清除history之后,.bash_history里仍会有历史记录

如何不让系统记录历史命令

# export HISTSIZE=0
# history
# [Note that history did not display anything]

3.使用Control+R来搜索命令

命令行中输入Control+R,然后输入过往命令的key word,你就很容易找到以前执行过的命令了

(reverse-i-search)`FND': FNDLOAD apps/apps 0 Y DOWNLOAD $FND_TOP/patch/115/import/affrmcus.lct PT_CUSTOM_FUC.ldt FND_FORM_CUSTOM_RULES function_name="INV_INVTOMAI"


转载请注明出处:http://blog.youkuaiyun.com/pan_tian/article/details/7715436

======EOF======


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值