I am trying to get my history in sync in multiple bash sections and things aren't working the way I expect.
Desired behavior, hitting esc-K in all bash sessions (same userid and machine) will use the same history.
Observed behavior: Esc-k shows the history of the current session, rather than the latest command in the HISTFILE.
Is there any way to store a command in bash history permanently? The actual scenario goes like this:-
I have a project in C and in order to configure my project, I have to run a very long command which is very difficult to remember. Once configured and build, I don't need that command for almost a month or so.
For the purposes of looking at which commands I am using the most, I'd like to keep a record of command I type in my bash history (even duplicates).
But, for sanity and ease of use, I still want to keep my ignoredups setting on.
Is there a way to automatically create two history files? With the "default" being no duplicates, and the full history elsewhere?
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
# 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
sh
I use mainly Terminator, and it's usually opened with 3 split terminal windows.
Few tips to use with bash command history.
Erase duplicates in your history file
If you repeat some times the same command, like I usually do when checking memory with
free -m
You will end up with a lot of those command repeated through your command history, and if you type
history
You may see an output like this:
I need to delete all commands in my history matching a string.
Both bash and zsh support a shorthand of not placing a command in history if you prepend it with a space. This works great across sessions (if you've setopt histignorespace). However, the command is still in the current session's history.
How can I avoid placing a command in the current session's history (or remove if after executing it)?
I believe that there are a large number of ways to prevent your bash history being recorded e.g. export HISTSIZE=0, how can I prevent users from hiding their bash history?