• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

How to change the number of commands stored in Bash History

by admin

The 2 environment variables which majorly affects the Bash History setting of saving the last run commands are HISTSIZE and HISTFILESIZE. The post is a short howto on how to change the number of commands remembered in the bash history.

HISTSIZE V/s HISTFILESIZE

The difference between HISTSIZE and HISTFILESIZE is that HISTSIZE limits the number of commands shown by the command history while HISTFILESIZE limits the number of commands which can be saved in $HISTFILE.

When one exits the bash, if there are more than $HISTSIZE number of commands which have been executed in the single bash session, the contents of $HISTFILE will be replaced by the $HISTSIZE number of commands. If there are less than or equal to $HISTSIZE number of commands in the bash session, these commands will be appended to $HISTFILE as long as $HISTFILESIZE permits.

If the number of commands to be appended to $HISTFILE plus the current existing number of commands in $HISTFILE is greater than $HISTFILESIZE, the oldest commands in $HISTFILE will be removed to ensure the latest commands are kept.

How to change the number of commands remembered in bash history

In bash, by default, the history commands are recorded in ~/.bash_history file. You can specify a different file other than ~/.bash_history by using the environment variable HISTFILE. The number of commands to be remembered in the history can be specified by the environment variable HISTSIZE. For example, add the following line to your .bash_profile:

# vi ~/.bash_profile
export HISTSIZE=500

Then exit the current shell and launch a new one Or you can run the .bash_profile file for the changes to take effect. The number of history commands to remember will be changed to 500.

# . .bash_profile

Changing the number of commands remembered in bash history in the current shell

One can also run the following command to force to append the history commands to $HISTFILE even though there are more than $HISTSIZE number of commands which have been executed in the bash session:

# shopt -s histappend
UNIX / Linux : Examples of bash history command to repeat last commands
CentOS / RHEL : How to disable BASH shell history
CentOS / RHEL : How to get the date and time of executed command in the history command output

Filed Under: CentOS/RHEL 6, CentOS/RHEL 7, Linux

Some more articles you might also be interested in …

  1. What are different Samba Server Types
  2. How To Check Swap Usage of Each Processes in Linux
  3. blkid Command Examples in Linux
  4. apt-file: command not found
  5. How to enable/disable wayland on Ubuntu 22.04
  6. gnome-software Command Examples in Linux
  7. nginx 504 gateway time-out
  8. CentOS / RHEL 7 : How to Create and Remove the LVM Mirrors Using lvconvert
  9. Configure dnsmasq to use different DNS Servers for some Domains (CentOS/RHEL)
  10. Defining System Jobs Using Cron under Linux

You May Also Like

Primary Sidebar

Recent Posts

  • powertop Command Examples in Linux
  • powertop: command not found
  • powerstat: command not found
  • powerstat Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright