I have my console configured with scroll back set as unlimited. Even so when I look at .bash_history there are only 1000 lines saved. I know I can go back further than this so my question is where are the lines beyond 1000 saved?
Budgie2
It is limited to 1000 entries and the oldest entries get overwritten when you reach this limit. You need to edit the settings…
You are talking about two different things.
- The
bash
history, which preserves the bash commands given in your interactivebash
sessions. - The scroll memory of your terminal emulator, which stores all lines that emerge on that terminal screen during that terminals existence.
And the bash
history is in ~/.bash_history
.
Hi and thanks. I had been under the impression I had been able to go back further and thought I had but I certainly cannot any longer.
This is a bit strange, if I edit the configuration as “unlimited” the rollback is restricted to 1000 but if I use the Fixed size I can set the size to whatever I want with a warning concerning using memory.
Unlimited should be just that. The warning exclamation mark suggests this, but the warning has changed now and indicates setting a temporary file location. I do not recall seeing this before but if I can set a temporary file, will this be preserved or deleted when console is closed?
Where do I find Settings>Configure Console>Temporary Files?
@Budgie2 you should have ~/.bash_history-nnnnn.tmp
files
Hi Henk,
Thanks for this. As you understand, I had not appreciated this. Please forgive my lax reference to ~/.bash_history.
So where can I find the scrolled lines from the terminal emulator.
You did not explain what you mean with “console”.
- The console of a non-GUI system;
- One of the virtual consoles of a GUI system;
- A terminal emulator in a desktop session (like xterm, konsole, …);
- Other …
Hi Malcolm,
Making heavy weather of this. I have no recollection of ever setting a temporary file although it makes sense but whatever the case I do not have any ~/.bash_history-nnnnn.tmp files.
I had been referring to the console but should have written Konsole. I believe this is a terminal emulator but the Settings>Configure Konsole>Temporary files is what I seek.
What is the problem?
Step 1:
Step 2:
Choose the bottom item of the menu in step 3:
And there you see :Temporary files.
I did not have the menu on my Konsole and had been looking in The System Settings.
I have now found the required information with the “hamburger menu” in the Konsole window. This enables me to set a directory so I shall try it now. I have set the file to
/home/alastair/.bash_history_02062024.tmp
I hope this is right.
Alastair, please take a look in the Bash Man Page – section “Shell Variables” –
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 a 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, to contain no more than that number of lines by removing the
oldest entries. The history file is also truncated to this size after writing it when a shell exits.
If the value is 0, the history file is truncated to zero size. Non-numeric values and numeric values
less than zero inhibit truncation. The shell sets the default value to the value of HISTSIZE after
reading any startup files.
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 beginning of the line and must match the complete line (no im-
plicit `*' is appended). Each pattern is tested against the line after the checks specified by HIST-
CONTROL are applied. In addition to the normal shell pattern matching characters, `&' matches the pre-
vious 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. The pattern matching honors the setting of the
extglob shell option.
HISTSIZE
The number of commands to remember in the command history (see HISTORY below). If the value is 0, com-
mands are not saved in the history list. Numeric values less than zero result in every command being
saved on the history list (there is no limit). The shell sets the default value to 500 after reading
any startup files.
HISTTIMEFORMAT
If this variable is set and not null, its value is used as a format string for strftime(3) to print the
time stamp associated with each history entry displayed by the history builtin. If this variable is
set, time stamps are written to the history file so they may be preserved across shell sessions. This
uses the history comment character to distinguish timestamps from other history lines.
Also, the section “HISTORY” –
HISTORY
When the -o history option to the set builtin is enabled, the shell provides access to the command history,
the list of commands previously typed. The value of the HISTSIZE variable is used as the number of commands
to save in a history list. The text of the last HISTSIZE commands (default 500) is saved. The shell stores
each command in the history list prior to parameter and variable expansion (see EXPANSION above) but after
history expansion is performed, subject to the values of the shell variables HISTIGNORE and HISTCONTROL.
On startup, the history is initialized from the file named by the variable HISTFILE (default ~/.bash_history).
The file named by the value of HISTFILE is truncated, if necessary, to contain no more than the number of
lines specified by the value of HISTFILESIZE. If HISTFILESIZE is unset, or set to null, a non-numeric value,
or a numeric value less than zero, the history file is not truncated. When the history file is read, lines
beginning with the history comment character followed immediately by a digit are interpreted as timestamps for
the preceding history line. These timestamps are optionally displayed depending on the value of the HISTTIME-
FORMAT variable. When a shell with history enabled exits, the last $HISTSIZE lines are copied from the his-
tory list to $HISTFILE. If the histappend shell option is enabled (see the description of shopt under SHELL
BUILTIN COMMANDS below), the lines are appended to the history file, otherwise the history file is overwrit-
ten. If HISTFILE is unset, or if the history file is unwritable, the history is not saved. If the HISTTIME-
FORMAT variable is set, time stamps are written to the history file, marked with the history comment charac-
ter, so they may be preserved across shell sessions. This uses the history comment character to distinguish
timestamps from other history lines. After saving the history, the history file is truncated to contain no
more than HISTFILESIZE lines. If HISTFILESIZE is unset, or set to null, a non-numeric value, or a numeric
value less than zero, the history file is not truncated.
The builtin command fc (see SHELL BUILTIN COMMANDS below) may be used to list or edit and re-execute a portion
of the history list. The history builtin may be used to display or modify the history list and manipulate the
history file. When using command-line editing, search commands are available in each editing mode that pro-
vide access to the history list.
The shell allows control over which commands are saved on the history list. The HISTCONTROL and HISTIGNORE
variables may be set to cause the shell to save only a subset of the commands entered. The cmdhist shell op-
tion, if enabled, causes the shell to attempt to save each line of a multi-line command in the same history
entry, adding semicolons where necessary to preserve syntactic correctness. The lithist shell option causes
the shell to save the command with embedded newlines instead of semicolons. See the description of the shopt
builtin below under SHELL BUILTIN COMMANDS for information on setting and unsetting shell options.
Also, please take note of the Bash builtin command “fc” – man page “bashbuiltins” …
> echo $HISTFILE
/home/???/.bash_history
>
> echo $HISTSIZE
1000
>
Hi @Budgie2 , viewed this thread about .bash_history & Co. Had the feeling that things might not got sorted out for you. While it’s good to have the RedHat tutorial on this, maybe I can more directly answer your question about the mismatch of having set “scroll back” to unlimited - as I have, too - versus having a ~/.bash_history file with only 1000 lines.
If you install Linux on most distros when you go in your terminal settings, mostly a scroll-back of 1000 is what you shall find. Adding a zero to have 10.000 or even set it to unlimited should be fine to remove the constraint of not having enough space to breathe. I think that is what you want, enough space, just in case, in the end you have other things to watch.
Now to the ~/.bash_history. Indeed without further ado you shall find a length of 1000 lines here by default. Let’s first change it to 10.000 only for user==budgie2 but not for root. We can do root later. Back to user==budgie2. You shall find $ echo $HISTSiZE ==> 1000 by default in most distros.
I recommend setting it to 10.000 by adding a line “export HISTSIZE=10000” without the outer double-quotes in your ~/.profile file. You should see $ echo $HISTSIZE ==> 10000 after your next login in your bash shell.
Next check $ echo $HISTFILESIZE . You shall find the “old” value 1000 here. Set it to 10.000 the same way as HISTSIZE before in your ~/.profile file adding another line “export HISTFILESIZE=10000” without the double-quotes and logout and login again.
Now you should find $ echo $HISTSIZE ==> 10000 AND $ echo $HISTFILESIZE ==> 10000 , too. Your ~/.bash_history file should now grow beyond 1000 lines until it reaches 10000 lines one day - or hours later, it depends.
If you want to do it for user==root AND user==budgie2 all in one go , I recommend setting “export HISTSIZE=10000” AND “export HISTFILESIZE=20000” (yes, double that, you heard right) in a file /etc/profile.local so that the original file /etc/profile stays untouched and can freely be updated by the distro bosses.
Why two different numbers (10000 vs 20000) here? Before you do it for all users incl root first check # echo $HISTSIZE and # echo $HISTFILESIZE as user==root , you shall find 1000 vs. 2000 , respectiely. Now peek into /root/.bash_history to get a glimpse of what’s written in there. Do # tail /root/.bash_history and you shall see the last 10 lines, the 1st one of these shall be a timestamp (long number of digits) the 2nd line shall be an old command you still remember somehow, the 3rd again a timestamp, the 4th again an old command of yours, etc. Peek into $ tail ~/.bash_history as user==budgie2 and you shall see 10 last lines of that file which shall be identical with the last 10 commands of yours - the timestamps won’t be there.
The difference has to do with history with date and time data for user==root and history without date and time data for everybody else. In most distros maybe not in each and all. But by and large , that’s what you’ll find.
If you do profile things , don’t be shy to logout and login again, don’t be lazy, else you shall waste your time asking why did you make changes which aren’t reflected by these $ echo $BLAH commands that we use here to check for success.
Hope it helps a little and at least clarifies the big picture here. - Bye, Regards, M.
Hi and very many thanks for your excellent and helpful reply. I wish all such calls for help were as constructive.
I have made some changes as you suggested.
What I do not understand is why when I have the scrolling settings in my profile set as Unlimited but they are still limited to 1000 lines, at least before I made your suggested changes.
Thanks again,
Budgie2
Hi @Budgie2
What I do not understand is why when I have the scrolling settings in my profile set as Unlimited but they are still limited to 1000 lines […].
Maybe it is worth while to underscore that what you have in the “Settings” of a modern terminal (-emulator) is how many lines you shall be able to scroll back in case you immediately want to check for something you wrote a little while ago. A setting of “unlimited” here will switch to a different internal mode of the terminal which will allocate more memory in RAM as more lines are created so that nothing must be deleted as long as the terminal session is on.
These things have nothing to do with what is stored in the older history mechanism you have when you use most Unix/Linux shells (bash, ksh, tcsh, fish, zsh, … ). The two are NOT coupled, the terminal does not know about the shell settings and vice versa. That seems not to be intuitive for someone dealing with back-scrolling and history mechanisms for the first time.
You also might want to recognize that the back-scrolling mechanism in terminals deals with the “here and now” of what was typed and output within a certain terminal tab or window, whereas the bash history mechanism is suited to persist what you typed in time. Furthermore, the history will survice logouts and reboots of your session or your system, respectively.
To illustrate, let me very briefly mention some bash history features which especially show you the you have very fine-grained power of what to retain for your future self and what should be forgotten as soon the tab or window closes.
So, $ history -c && exit will close the terminal (tab / window) WITHOUT storing what was typed THIS TIME AROUND. So maybe Tuesday you work in bash and at the end of the day you leave with just $ exit . On Wednesday you work and leave with $ history -c && exit , so all of Wednesday will be forgotten. On Thursday you di as on Tuesday. So, on Friday you shall find your old commands from Tuesday and from Thursday, however, those from Wednesday you won’t.
There is another mechanism which allows for even more finegrained control. Simply starting a command with a space effectively prevents it from being recorded in the history.
These two features alone might suffice to illustrate how different conceptually the bash history mechanism is from a terminal back-scrolling setting. Knowing this might give you back some intuition which might have been missing when you started your history journey .
Hope it helps a little, again , Regards , M.
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.