• MacOs
  • Step-by-Step: Increase MacOS Zsh History Limit

Great question! On macOS (using Zsh by default), your shell command history might be limited to the last 500 commands, but you can easily increase that limit.

Let’s walk through how to store and recall more commands in your Terminal history.


πŸ› οΈ Step-by-Step: Increase Zsh History Limit

1. Open Terminal

2. Edit your Zsh configuration file

Run this command:

nano ~/.zshrc

3. Add or Update These Settings

Paste or update the following lines in your .zshrc file:

# Increase the number of lines saved in history
HISTSIZE=10000         # Number of commands to remember in memory (in-session)
SAVEHIST=10000         # Number of commands to save to the history file
HISTFILE=~/.zsh_history  # File where history is stored
alias history='history 1'

πŸ” You can increase 10000 to even more (like 50000) if needed.

4. Save and Exit

  • Press Control + X, then Y, then Enter to save and exit.

5. Apply the Changes

Run:

source ~/.zshrc

βœ… Done! Now your Terminal will:

  • Keep up to 10,000 commands in session.
  • Save them in ~/.zsh_history across reboots.

πŸ” Want to Check Current Limits?

Run this in Terminal:

echo $HISTSIZE
echo $SAVEHIST

πŸ“¦ For Bash Users (if you're using bash instead of zsh)

Edit your ~/.bash_profile or ~/.bashrc:

nano ~/.bash_profile

Add:

HISTSIZE=10000
HISTFILESIZE=20000

Then save and source ~/.bash_profile.


Let me know if you'd also like to enable timestamped history or search history by keywords!

I understand you're experiencing an issue where the history command in your macOS Terminal displays only the last 15 commands. This behavior is due to the default settings of the Zsh shell, which macOS now uses by default. Let's explore how to adjust these settings to display a more extensive command history.

Understanding the Default Behavior

In Zsh, invoking the history command without arguments lists a limited number of recent commands, typically the last 15. This design aims to provide a quick view without overwhelming the user with too much information.

Displaying a Larger Command History

To view more than the default number of commands, you can use the history command followed by a number:

  • View the Last 100 Commands:

      history 100

    This command displays the most recent 100 commands.

  • View All Commands from the Beginning:

      history 1

    This command lists all commands stored in your current session's history.

Making the Change Permanent

If you prefer the history command to display all past commands by default, you can create an alias in your Zsh configuration file:

  1. Open the Zsh Configuration File:

       nano ~/.zshrc
  2. Add the Alias:
    Append the following line to the file:

       alias history='history 1'
  3. Save and Exit:

    • Press Control + O to save the changes.
    • Press Enter to confirm.
    • Press Control + X to exit the editor.
  4. Apply the Changes:

       source ~/.zshrc

By setting this alias, every time you type history, it will execute history 1, displaying all commands from your history.

Additional Considerations

  • History File Settings: Ensure that your history settings allow for a larger number of commands to be stored. In your ~/.zshrc file, you can set:

      HISTSIZE=10000
      SAVEHIST=10000
      HISTFILE=~/.zsh_history

    These lines configure Zsh to remember up to 10,000 commands in memory and save them to your history file.

  • Viewing the History File Directly: If you want to view all past commands without adjusting settings, you can directly inspect the history file:

      cat ~/.zsh_history

    This command displays all commands stored in the history file.

By implementing these adjustments, you should be able to view and retain a more extensive command history in your macOS Terminal sessions.