.bash_history: 他总是写下我曾经表演过的每个团队吗?

我希望能够查看队伍的历史 /直到用户的开始/.

有没有保证 .bash_history 将继续添加?

如果文件开始到来时有限制 /我希望从一开始/ , 有没有办法去除这个限制?
已邀请:

江南孤鹜

赞同来自:

有许多环境变量可以控制故事如何工作 bash. 以下是来自手册页的相应摘录。 bash:


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.


要直接回答您的问题:

不,没有保修,因为故事可以禁用,可能无法存储一些命令 /例如,开始 whitespace/, 它可能施加对故事的大小。

至于限制故事的大小:如果你关闭
HISTSIZE


HISTFILESIZE

:


unset HISTSIZE
unset HISTFILESIZE


你不允许 shell 你的故事文件。 但是,如果您有一个实例 shell, 使用这两个变量,它将在离开时继续您的故事,因此解决方案相当脆弱。 如果您绝对需要维持长期历史 shell, 你不必依赖 shell 并定期复制文件 /例如,使用任务 cron/ 在一个安全的地方。

故事的截断始终首先删除上述反馈页面中所示的最旧记录。

石油百科

赞同来自:

man bash

是你的朋友:变量
HISTFILESIZE

:

历史文件中包含的最大行数。 当为该值分配此变量时,历史文件被截断,删除最多
旧记录不超过此行数。 默认值为500。 在录制后,历史文件也被截断到此大小
互动的产出 shell.

快网

赞同来自:

如果您希望将所有会话中的所有命令添加到即时故事中 /这样你就可以在另一个会话中使用命令/, 您可以放在您的以下行 .bashrc :


unset HISTSIZE
unset HISTFILESIZE
HISTCONTROL=erasedups

# append to the history file, don't overwrite it
shopt -s histappend
# multi-line commands should be stored as a single command
shopt -s cmdhist

# sharing of history between multiple terminals
# histfile has to be read and saved after each command execution
PROMPT_COMMAND="history -n; history -w; history -c; history -r; $PROMPT_COMMAND"


有关这些命令的更多信息可以在此处找到:
https://unix.stackexchange.com ... 55135

郭文康

赞同来自:

也要注意。 默认情况下,如果您使用多个登录会话 /我通常 2 或者 3 putty windows 输入了同一台服务器/, 他们看不到对方的故事。

此外,事实证明,当我从所有的炮击中出发时,最后一个出来,它被保存回文件 /即,当我开始第二天工作时,它是可见的/. 因此,我假设 bash 将历史记录存储在内存中,然后在离开时重置为文件,至少这是我基于我所看到的假设。

喜特乐

赞同来自:

Adam 建议取消规模限制并没有减少它,但是
您可以避免其他实例 shell, 为了改变 HISTSIZE, HISTFILESIZE, ...
, 通过安装它们标志 readonly 在 /etc/profile.


unset HISTSIZE
unset HISTFILESIZE
readonly HISTFILE HISTFILESIZE HISTSIZE HISTCONTROL HISTIGNORE HISTTIMEFORMAT

要回复问题请先登录注册