Using Linux History

One really nice feature of Linux is its ability to maintain a history of the commands you typed in. Its like a little journal of your linux journey and you can easily access and browse with some handy commands. There are some commands that you’ll run often and being able to reference those can be extremely useful. We’ve written about leveraging your history before in our article terminal history auto suggestions as you type with oh my zsh so we’re big fans of being efficient and reusing commands in our terminal. Let’s check out some info about history:

Simply typing history will show you a list of all your executed commands in linux.

> history
1 ls
2 cd ../
3 man ls
4 clear
5 ggpush

A very quick tip is to use the pipe (written about here) to be able to search on what the history output shows us:

> history | grep 'ls'
1 ls
2 man ls

We use ripgrep which is an extremely fast and easy to use search tool so our search would be:

> history | rg 'ls'

If you want to customize how your history output displays, linux gives you some options you can specify to change the display:


# %F Equivalent to %Y - %m - %d
# %T Replaced by the time ( %H : %M : %S )

You would specify this in your .bashrc or your .bash_profile. You can also set an option to ignore duplicate commands in your history:

export HISTCONTROL=ignoredups

Set the number of commands stored in your history with the HISTSIZE variable:

export HISTSIZE=50000

See a list of other bash variables here

Instagram Post