问题描述
我希望能够通过我的命令历史记录看(所有的方式返回给用户的开头)。
I'd like to be able to look through my command history (all the way back to the beginning of the user).
有没有保证,.bash_history的将继续追加到?
Is there any guarantee that .bash_history will continue to be appended to?
如果有该文件将开始被截断(希望从一开始)的限制有没有办法消除限制?
If there is a limit where the file will start to be truncated (hopefully from the beginning) is there a way to remove that limit?
推荐答案
有是一个数字,历史上控制在bash是如何工作的环境变量。从bash的手册页相关的摘录如下:
There is a number of environment variables that control how history works in bash. Relevant excerpt from bash manpage follows:
HISTCONTROL
A colon-separated list of values controlling how commands are saved on the history list. If the list of values includes ignorespace, lines which
begin with a space character are not saved in the history list. A value of ignoredups causes lines matching the previous history entry to not be
saved. A value of ignoreboth is shorthand for ignorespace and ignoredups. A value of erasedups causes all previous lines matching the current
line to be removed from the history list before that line is saved. Any value not in the above list is ignored. If HISTCONTROL is unset, or does
not include a valid value, all lines read by the shell parser are saved on the history list, subject to the value of HISTIGNORE. The second and
subsequent lines of a multi-line compound command are not tested, and are added to the history regardless of the value of HISTCONTROL.
HISTFILE
The name of the file in which command history is saved (see HISTORY below). The default value is ~/.bash_history. If unset, the command history
is not saved when an interactive shell exits.
HISTFILESIZE
The maximum number of lines contained in the history file. When this variable is assigned a value, the history 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.
HISTIGNORE
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 begin-
ning of the line and must match the complete line (no implicit `*' is appended). Each pattern is tested against the line after the checks speci-
fied by HISTCONTROL are applied. In addition to the normal shell pattern matching characters, `&' matches the previous history line. `&' may be
escaped using a backslash; the backslash is removed before attempting a match. The second and subsequent lines of a multi-line compound command
are not tested, and are added to the history regardless of the value of HISTIGNORE.
HISTSIZE
The number of commands to remember in the command history (see HISTORY below). The default value is 500.
要直接回答你的问题:
没有没有保证,因为历史可以被禁用,某些命令可能不被保存(例如开头的空格),并有可能成为实行历史上大小有限制。
No there isn't a guarantee, since history can be disabled, some commands may not be stored (e.g. starting with a whitespace) and there may be a limit imposed on the history size.
至于历史上大小限制:如果您没有设置 HISTSIZE
和 HISTFILESIZE
:
As for the history size limitation: if you unset HISTSIZE
and HISTFILESIZE
:
unset HISTSIZE
unset HISTFILESIZE
你prevent从截断历史文件的外壳。但是,如果您具有这两个变量设置一个shell中运行的实例,它会截断你的历史而退出,因此该解决方案是非常脆。如果你绝对必须保持长期的外壳的历史,你不应该依赖于外壳并定期复制的文件(例如,使用cron作业)到安全位置。
you'll prevent the shell from truncating your history file. However, if you have an instance of a shell running that has these two variables set, it will truncate your history while exiting, so the solution is quite brittle. In case you absolutely must maintain long term shell history, you should not rely on shell and copy the files regularly (e.g. using a cron job) to a safe location.
历史截断总是先删除最早的条目在手册页摘录上述
History truncation always removes oldest entries first as stated in the manpage excerpt above.
这篇关于.bash_history的:它总是记录下每一个我曾经发出命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!