Unix & Linux: Is there a way to set the size of the history list in bash to more than 5000 lines?
Channel: Roel Van de Paar
Date: 17/08/2020

Unix & Linux: Is there a way to set the size of the history list in bash to more than 5000 lines?


The Question: No matter how much I set the HISTSIZE environment variable to be larger than
5000, when printing the history list with the history builtin, it prints only
the last 5000 commands. I need that because I often have a large .bash_history
which exceeds 5000 lines, and sometimes one needs to address an early command
by pressing Ctrl-R, but if that command is more than 5000 commands earlier, I
can't access it using that mechanism. I know I can use grep on the
.bash_history, but I think the Ctrl-R mechanism would be much more faster (and
convenient). I use gnu bash version 4.1.
That is the full content of my .bashrc file:
 #!/bin/bash
 # ~/.bashrc: executed by bash(1) for non-login shells.
 # see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
 # for examples

 # If not running interactively, don't do anything
 [ -z "$PS1" ] && return

 # don't put duplicate lines in the history. See bash(1) for more options
 # ... or force ignoredups and ignorespace
 #HISTCONTROL=ignoredups:ignorespace:erasedups

 # append to the history file, don't overwrite it
 shopt -s histappend

 # for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
 HISTSIZE=50000
 HISTFILESIZE=500000

 # check the window size after each command and, if necessary,
 # update the values of LINES and COLUMNS.
 shopt -s checkwinsize

 # make less more friendly for non-text input files, see lesspipe(1)
 [ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"

 # set variable identifying the chroot you work in (used in the prompt
below)
 if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
 debian_chroot=$(cat /etc/debian_chroot)
 fi

 # set a fancy prompt (non-color, unless we know we "want" color)
 case "$TERM" in
 xterm-color) color_prompt=yes;;
 esac

 # uncomment for a colored prompt, if the terminal has the capability;
turned
 # off by default to not distract the user: the focus in a terminal window
 # should be on the output of commands, not on the prompt
... (Please watch the video for the full question)

Solutions: Please watch the whole video to see all solutions, in order of how many people found them helpful

== This solution helped 5 people ==
Try both HISTFILESIZE and HISTSIZE.

With thanks & praise to God, and with thanks to the many people who have made this project possible! | Content (except music & images) licensed under cc by-sa 3.0 | Music: https://www.bensound.com/royalty-free-music | Images: https://stocksnap.io/license & others | With thanks to user ztank1013 (https://unix.stackexchange.com/users/10790), user treat your mods well (https://unix.stackexchange.com/users/3071), user Tim Post (https://unix.stackexchange.com/users/3150), user Thomas (https://unix.stackexchange.com/users/151151), user Marwan Tanager (https://unix.stackexchange.com/users/10798), user javeed shakeel (https://unix.stackexchange.com/users/252732), user FanDeLaU (https://unix.stackexchange.com/users/66917), user Emil Mikulic (https://unix.stackexchange.com/users/82620), user bahamat (https://unix.stackexchange.com/users/3309), and the Stack Exchange Network (http://unix.stackexchange.com/questions/20861). Trademarks are property of their respective owners. Disclaimer: All information is provided "AS IS" without warranty of any kind. You are responsible for your own actions. Please contact me if anything is amiss at Roel D.OT VandePaar A.T gmail.com.