本文翻译自:Unlimited Bash History [closed]

I want my .bash_history file to be unlimited. 我希望我的.bash_history文件无限制。 eg So I can always go back and see how I built/configured something, or what that nifty command was, or how some command broke something weeks ago. 例如,我总是可以回去看看我是如何构建/配置某些东西,或者那个漂亮的命令是什么,或者几周之前某些命令是如何破坏的。 How do I change this setting? 如何更改此设置?


#1楼

参考:https://stackoom.com/question/dgG1/无限的Bash历史-关闭


#2楼

Set HISTSIZE and HISTFILESIZE in .bashrc to an empty string: 将.bashrc中的HISTSIZEHISTFILESIZE设置为空字符串:

HISTSIZE=
HISTFILESIZE=

In bash 4.3 and later you can also use HISTSIZE=-1 HISTFILESIZE=-1 : 在bash 4.3及更高版本中,您还可以使用HISTSIZE=-1 HISTFILESIZE=-1

n.  Setting HISTSIZE to a value less than zero causes the history list to beunlimited (setting it 0 zero disables the history list).o.  Setting HISTFILESIZE to a value less than zero causes the history file sizeto be unlimited (setting it to 0 causes the history file to be truncatedto zero size).

#3楼

After many large, ugly iterations and weird edge cases over the years, I now have a concise section of my .bashrc dedicated to this. 经过多年来的许多大型,丑陋的迭代和奇怪的边缘情况,我现在有一个专门用于此的.bashrc的简洁部分。

First, you must comment out or remove this section of your .bashrc (default for Ubuntu). 首先,您必须注释掉或删除.bashrc的此部分 (Ubuntu的默认值)。 If you don't, then certain environments (like running screen sessions) will still truncate your history: 如果不这样做,那么某些环境(如运行screen会话)仍会截断您的历史记录:

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
# HISTSIZE=1000
# HISTFILESIZE=2000

Second, add this to the bottom of your .bashrc: 其次, 将其添加到.bashrc的底部:

# Eternal bash history.
# ---------------------
# Undocumented feature which sets the size to "unlimited".
# http://stackoverflow.com/questions/9457233/unlimited-bash-history
export HISTFILESIZE=
export HISTSIZE=
export HISTTIMEFORMAT="[%F %T] "
# Change the file location because certain bash sessions truncate .bash_history file upon close.
# http://superuser.com/questions/575479/bash-history-truncated-to-500-lines-on-each-login
export HISTFILE=~/.bash_eternal_history
# Force prompt to write history after every command.
# http://superuser.com/questions/20900/bash-history-loss
PROMPT_COMMAND="history -a; $PROMPT_COMMAND"

Note: every command is written immediately after it's run, so if you accidentally paste a password you cannot just "kill -9 %%" to avoid the history write, you'll need to remove it manually. 注意:每个命令在运行后立即写入,因此如果您不小心粘贴了密码,您不能只是“杀死-9 %%”以避免历史记录写入,您需要手动删除它。

Also note that each bash session will load the full history file in memory, but even if your history file grows to 10MB (which will take a long, long time) you won't notice much of an effect on your bash startup time. 另请注意,每个bash会话都会在内存中加载完整的历史记录文件,但即使您的历史文件增长到10MB(这需要很长很长时间),您也不会注意到对bash启动时间有太大影响。


#4楼

There are (at least) two relevant env vars here: 这里至少有两个相关的环境变量:

  • HISTSIZE: the number of entries in the history file HISTSIZE:历史文件中的条目数
  • HISTFILESIZE: the number of lines in the history file HISTFILESIZE:历史文件中的行数

I think that we can agree that the term unlimited is often the same as very big (or do you have unlimited file storage?). 我认为我们可以同意无限期这个词通常与非常大 (或者你有无限的文件存储?)。 So just set the values very large. 所以只需设置非常大的值。


#5楼

As Jörg Beyer mentioned above, HISTSIZE and HISTFILESIZE are key. 正如HISTSIZE在上面提到的, HISTSIZEHISTFILESIZE是关键。

In addition, you should definitely check out the environmental variable HISTCONTROL , which lets you do cool things like not store duplicate history commands ( HISTCONTROL=erasedups ). 另外,你一定要查看环境变量HISTCONTROL ,它可以让你做一些很酷的事情,比如不存储重复的历史命令( HISTCONTROL=erasedups )。 There's no point having unlimited history if you have to browse through hundreds of lines of cd .. or similar. 如果您必须浏览数百行cd ..或类似内容,那么无限的历史就没有意义了。

Links: here , and working with bash history . 链接: 在这里 ,并使用bash历史记录 。 The bash Variable FAQ is also worth browsing . bash Variable FAQ也值得浏览 。

无限的Bash历史[关闭]相关推荐

  1. bash历史命令数_如何使用Bash历史记录命令

    bash历史命令数 Bash历史悠久. 也就是说,它是一个老祖先的外壳(Bourne外壳),但是它还有一个很棒的history命令,它根据其功能数量超过了所有其他外壳历史接口. Bash版本的hist ...

  2. linux 使用bash命令关闭TCP连接

    在进程中关闭tcp连接比较简单,直接调用socket的API即可关闭,或不发送心跳机制. 有时候为了测试异常环境,在不断网的情况下,如何使用bash命令关闭TCP的连接呢? 下面谈两种使用bash命令 ...

  3. 使用Bash编写Linux Shell脚本-4.脚本初探

    4.  脚本初探 我第一次接触计算机还是在高中的学校内,学校购买了一台崭新的TRS-80,Model I,安装在图书馆内,免费提供所有的人使用,我记得我按照一本手册打印出了我的第一个BASIC程序. ...

  4. ubuntu的bash参考手册

    转自http://blog.csdn.net/laoyiin?viewmode=contents 方便学习,这些命令真是头大,想看的看看不想看就当手册了,哈哈 1 简介 •什么是Bash:Bash的一 ...

  5. 进化过程中的历史遗留问题

    从前!从前!从前! 历史--高深莫测的,漆黑一团的历史! 沉睡的尸骨和历史的影子! 历史--无限伟大的历史! 今天的一切,都是历史造就的吗? --瓦特·惠特曼(Walt Whitman):<印度 ...

  6. Bash审计与命令记录

    翻译原出处:www.pointsoftware.ch/de/howto-bash-audit-command-logger/ 翻译并整理了一下,水平有限,多请见谅. 有一个完整的输入命令记录在很多情况 ...

  7. 将今天写进历史,即可得出现在的世界是数字的

    [+]查看原图 世界是什么?数千年前,尼罗河畔,那些长髯飘飘的学者们便在争论这个难题.有的说,世界是火,有火才有生命:有的说,世界是水,海是我们最初的家园:还有的说,世界是空气.是泥--一个叫毕达哥拉 ...

  8. linux终端关闭时为什么会导致在其上启动的进程退出?

    现象 经常在linux下开发的人应该都有这样的经验,就是在终端上启动的程序,在关闭终端时,这个程序的进程也被一起关闭了.看下面这个程序,为了使进程永远运行,在输出helloworld后,循环调用sle ...

  9. centos查看历史指令记录_CentOS清除SSH登录记录、历史命令及日志缓存

    清除 SSH 登录记录 SSH 登录日志以二进制方式存储在以下文件内,需要使用对应命令查看,不然会显示乱码. 日志文件 查看命令 日志内容 /var/log/wtmp last 登录成功日志,包含用户 ...

最新文章

  1. StringUtils
  2. Eclipse 导入逆向工程
  3. 微信说中国人的国庆长假 境内游西湖外滩上榜
  4. 文件资源管理右键卡死无响应
  5. python编程入门经典 评分-豆瓣评分爆炸!Python+机器学习经典图书
  6. 灵魂拷问:用移位来代替除法运算真的效率高吗?Java 编译器到底有没有做除法优化?
  7. YBTOJ洛谷P4074:糖果公园(树上莫队)
  8. Hibernate的关联映射--一对多、
  9. 【kafka】kafka 建立很多很多消费组 会怎么样
  10. NVIDIA-SMI has failed because it couldn‘t communicate with the NVIDIA driver
  11. 刘海洋《Latex入门》学习笔记1
  12. win10中修改mac地址
  13. 光纤线上线缆标识信息解读
  14. C# WinAPI 编程详解(一)
  15. 国内知名流程管理软件-汇总介绍
  16. matlab 求公切线方程,【原创】绘制两圆公切线MATLAB代码
  17. [Vulfocus解题系列] 所复现漏洞总结
  18. 进程间的通信(管道通信)
  19. Boosting和Bagging区别
  20. 【NVMe2.0b 16-1】Get Log Page

热门文章

  1. 如何开发一个属于自己的小程序
  2. 【剑指offer-Java版】37两个链表的第一个公共结点
  3. Android 10.0系统启动之init进程-[Android取经之路]
  4. Android性能优化典范第四季
  5. 复制链接到safari浏览器打开_JS实现复制到剪贴板(兼容FF/Chrome/Safari所有浏览器)...
  6. 北风设计模式课程---单一职责原则
  7. 三分钟学会用SpringMVC搭建最小系统(超详细)_转载
  8. iOS macOS的后渗透利用工具:EggShell
  9. URL参数解析与反解析
  10. android clipdrawable 小例子