Skip to main content
Account
Guide

Tip 2: History Forgets Common Commands

David Flanagan Jan 02, 2020 1 min read

With Tip 1, we looked at how we can switch our history between local directory and global.

Regardless of which you’re using, some stuff just doesn’t belong there; right?

Do you really use to Control + r or Up to find ls, cd, or rm?

No. The answer is no.

Keeping History Clean

Here are 3 short and sweet options you can configure in your zshrc file to keep your history lean, mean, and clean.

Forget Duplicate Commands

Zsh can de-duplicate your command history :smile:

Enable this behaviour with setopt HIST_IGNORE_DUPS

Forget Common Commands

The next approach to keeping our history clean is using HISTIGNORE.

Terminal window
HISTIGNORE="&:ls:[bf]g:exit:reset:clear:cd:cd ..:cd..:zh"

This is a global list of commands and patterns that you don’t want to keep.

Use this for all your trivial commands that don’t warrant searching later.

Forget Space Commands

Another great feature of Zsh is hiding commands preceding with a Space

Enable this behaviour with setopt HIST_IGNORE_SPACE

Terminal window
# Not stored in history
ls
# Stored in history
ls

You can find more examples of tweaking your history here

Published Jan 02, 2020

Related Articles

Rawkode Academy newsletter

Academy publications by email

Get an email when Rawkode Academy publishes new tutorials, articles, and videos.

Loading email signup. If it does not load, manage email preferences in account settings.