Master Linux Bash History with historyctl, HISTFILE, and Shortcuts

Read the full article: Master Linux Bash History with historyctl, HISTFILE, and Shortcuts

Bash history does a lot more than scroll up. Learn how to configure HISTSIZE, timestamps, multi-terminal sync, and search shortcuts to get real productivity gains at the command line. continue reading.
7 Likes

Nice article, I learned new stuff :face_with_monocle:

3 Likes

Finally got a chance to read through this, excellent article as always! There was an early topic on the forums about what your most used “command” is. My answer is Ctrl+R; I feel like I rely on that more than I do anything else!

There have been times where I could have sworn I ran a specific command, only to find that it’s not in my history anywhere! I’ll be updating all of my ~/.bashrc files to include:

# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth

# append to the history file, don't overwrite it
shopt -s histappend

# Wrtie and reload history after each command
PROMPT_COMMAND="history -a; history -c; history -r${PROMPT_COMMAND:+; $PROMPT_COMMAND}"

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=10000
HISTFILESIZE=20000

This seems like enough for me test and see if this fits my use cases, thanks for posting this article!

4 Likes

I haven’t used ALL of the features of bash history, but the ones I use have been fine tuned since 1995, when I gradually started moving from ksh to bash. Since I’ve had a history with sh going back to 1982 and ksh since the mid to late eighties, I’ve definitely had a preference toward sh-based shells.

When I did get to use csh I liked the fact that it had easy command recall, but it was terrible for use with scripts, so I was delighted when I started using ksh. However, in the mid to late 1990s, probably somewhere around 1997, bash caught up to ksh in capabilities and shortly thereafter exceeded ksh, especially once it received high exposure with increasingly popular Linux systems.

I tried zsh and tcsh too. Once again with tcsh, too bad that the scripting language is so terrible; otherwise I felt that in the interactive space at the last point that I used exclusively UNIX systems in the workplace AND had access to them as a super user tcsh ran well then. So did zsh, but not so much to raise it’s appeal and replace bash.

While I’m on the topic, I experimented with fish in the past week. The Endeavour OS instance of fish is the only place where I experienced a satisfactory experience; I couldn’t get it to do anything useful on MX Linux at all, so that told me enough - if it can’t be easily installed and configured universally, it’s not worth the effort at all.

Anyway, back to your work; it’s an excellent essay on what you can do with Bash and particularly with Bash history - another winning article in your collection!

4 Likes