brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: HISTIGNORE keeps boring commands out of your bash history

Bash
~/tips/tip-bash-histignore-skip-commands-in-history

export HISTIGNORE='ls*:pwd:cd*'

Lists command patterns that bash never saves in the history, like ls, pwd and exit.

My shell history fills up with ls, pwd and cd, and the commands I actually want to find again drown in them. Bash can leave the boring ones out.

export HISTIGNORE='ls*:pwd:cd*'

The manual describes HISTIGNORE as a colon-separated list of patterns. A command line that matches one of them is not saved. Each pattern is anchored at the start of the line and must match the complete line, because bash does not add a * for you. So ls only hides a bare ls, and ls* hides ls -la as well.

In an interactive shell that reads these lines: ls /nonexistent_zz, pwd, echo hi, cd /tmp, history, the history afterwards holds only echo hi and history.

Two details from the manual. A pattern of & matches the previous history line, so HISTIGNORE='&' does the same as HISTCONTROL=ignoredups, and '[ ]*' is the same as ignorespace. The patterns also honour the extglob option.

The caveat is that ignored commands are gone for good. If you hide cd* and later want to know where you were, the history cannot tell you. I’d keep the list short and put it in ~/.bashrc so it applies to every new shell.

Further reading: Bash reference manual

More Bash tips echo {01..10} cmd > file 2>&1 #rsync -av --delete /srv/media/ /mnt/backup/media/ APP_HOST=example.com set -e All Bash tips (52) All topics

Link