Home > Linux > Linux Bash: log commands of all shells immediately to a single command history

Linux Bash: log commands of all shells immediately to a single command history

One of the useful features of Linux Bash is to search the command history. For interactive search press Ctrl+R, start typing your command and the last executed command matching it will pop up (you can cycle through multiple commands that match your typing pressing Ctrl+R again). Although the feature is useful we like to tune it’s default config a bit in order to improve user experience. In the default config the history somehow depends on a) the shell instance you are using (this makes a difference if you use multiple shells at the same time), and b) commands do not get logged immediately to the history. We like to have a command typed in one shell available in the history of all shells immediately.

1. Append all shell commands of all shell to the history (already part of many newer distro releases including Ubuntu 14.04)
Append the following line to your ~/.bashrc file:

shopt -s histappend

2. Append all shell commands to the history immediately
Append the following line to your ~/.bashrc file:

PROMPT_COMMAND="history -a;$PROMPT_COMMAND" 

Each Bash opened after these changes will log all commands for all shell instances immediately.

Thx to darksider15 for having the original idea a long time ago.

  1. No comments yet.
  1. August 12, 2016 at 15:39

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: