C'è un numero di variabili di ambiente che controllano come funziona la cronologia in bash. estratto rilevante da bash manpage segue:
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.
per rispondere alle vostre domande direttamente:
No, non c'è una garanzia, poiché la storia può essere disattivato, alcuni comandi non possono essere conservati (ad esempio, a partire da uno spazio bianco) e potrebbe esserci un limite imposto alle dimensioni della cronologia.
Per quanto riguarda la limitazione di dimensione storia: Se viene disattivata HISTSIZE
e HISTFILESIZE
:
unset HISTSIZE
unset HISTFILESIZE
si evitare che la shell troncare il file di storia. Tuttavia, se si ha un'istanza di una shell in esecuzione con queste due variabili impostate, troncherà la cronologia mentre si esce, quindi la soluzione è piuttosto fragile. Nel caso in cui si debba assolutamente conservare la cronologia della shell a lungo termine, non si deve fare affidamento sulla shell e copiare i file regolarmente (ad esempio utilizzando un cron job) in una posizione sicura.
Il troncamento cronologico rimuove sempre prima le voci meno recenti, come indicato nell'estratto di manpage sopra.
fonte
2011-11-17 14:27:03
Questa domanda è più adatto per [unix.stackexchange.com] (http://unix.stackexchange.com/) –