Recommended Settings to Supercharge Bash History

When working daily in the terminal on Linux or macOS, the “history" feature for recalling previously executed commands is indispensable.
However, with the default settings, the number of history entries is small, meaning those useful records quickly disappear. Additionally, it can be frustrating to use because you cannot tell when a command was executed.


目次

Objectives

  • Long-term storage of previously executed commands

  • Clear display of execution dates and times

  • Properly retain history even when multiple terminals are open

Issues

  1. By default, the number of history entries (HISTSIZE) is small, retaining only a few thousand lines

  2. There is no date and time information, making it difficult to know when a command was run

  3. When using multiple terminals, only the history of the last closed window is saved, and other history may be lost


Solution: Configuration Example

Add the following settings to ~/.bashrc and apply them.

# Add to ~/.bashrc
export HISTSIZE=100000 # Number of entries to keep in memory
export HISTFILESIZE=200000 # Number of entries to save in ~/.bash_history
shopt -s histappend # Append instead of overwriting
export PROMPT_COMMAND="history -a" # Save after every command execution
export HISTTIMEFORMAT="%F %T " # Display date and time

To apply the settings, run the following:

source</span> ~/.bashrc

Verifying the Effects

1. Check if the history size has increased

echo $HISTSIZE $HISTFILESIZE

Output example:

100000 200000

2. Check if dates and times are displayed in the history

history | head

Output example:

 1000 2025-08-18 20:12:35 ls -l
1001 2025-08-18 20:12:40 git status

Conclusion

  • Increasing HISTSIZE and HISTFILESIZE allows for long-term history storage

  • HISTTIMEFORMAT makes command execution times easy to understand

  • Using histappend and PROMPT_COMMAND="history -a" prevents history from being lost across multiple terminals

Just by adding these 5 lines to your .bashrc, terminal work becomes significantly more comfortable.
If you want to make better use of your past commands, please give it a try.