Mac OSX Terminal/iTerm Infinite History

Aug 29, 2017 17:00 · 230 words · 2 minutes read osx unix linux terminal iterm mac quicktips

Infinite History. Why?

Have you ever needed to run an a command you executed some time ago only to find out it’s not in your history anymore?

Changing this default behaviour takes a minute. And it’s not like you’re gonna run out of space by saving every single command you ever executed on your shell.

This is a quick guide on how to enable infinite history on your system. Keep in mind your choice of terminal (Default OSX Terminal, iTerm, Terminator, MacTerm…) is irrelevant.



Step By Step

1 - Open up any terminal application (iTerm is my personal preference)

2 - Edit your .bash_profile. Nano will do

nano ~/.bash_profile

3a - Paste the following 2 lines at the end of the file (which may be empty) and save

HISTFILESIZE=

3b - In case the above line disables your history, use this instead

HISTFILESIZE=100000000

(100 Million ought to do it.. Right?)


.bash_profile



Accessing the full history

By default, the history command will show the 500 most recent commands. You can access the full version of your history by viewing the .bash_history file.

cat ~/.bash_history

Or

open ~/.bash_history



Protip - Rerunning Commands

Did you know you can actually run a previously used command by referencing it’s line number in the .bash_history file?

You can use !<number>

In the example below I rerun command number 6087 which is echo "hello world by using !6087:

Rerunning Commands