Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 09-06-2016, 04:33 PM   #16
LQ Veteran
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled

Originally Posted by dedec0 View Post
The configuration means that, but it does not work in cases with parallel sessions.
Oh, "that". Yes, I live in terminals (SysAdmin) and history being "in sync" never worked for me.
Old 09-06-2016, 09:36 PM   #17
Senior Member
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, Fedora, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, Vsido, tinycore, Q4OS
Posts: 3,549

Rep: Reputation: 1577Reputation: 1577Reputation: 1577Reputation: 1577Reputation: 1577Reputation: 1577Reputation: 1577Reputation: 1577Reputation: 1577Reputation: 1577Reputation: 1577
So, if that is indeed the case the BASH developers may decide NEVER to solve the problem, because it is not in fact any kind of bug.
What the OP may require then, is some kind of process that removes the dups as the last parallel session closes and the history file is closed and inactive.
Old 09-07-2016, 02:33 PM   #18
Senior Member
Registered: May 2007
Posts: 1,081

Original Poster
Rep: Reputation: 36
Post Steps to make history duplicates, when it should not have

I am using Gnome 2's gnome-terminal, this gives me easy open/close/change in terminal sessions: ctrl+shift+t open a new terminal; "[ctrl+c] ctrl+d" closes it; alt+[N] changes to other sessions, keeping the current one open.

The relevant parts of my .bashrc, .bash_login and .bash_logout are:

# many parts removed, this MAY not work as is for the missing parts => point it

# I am not sure what this line do, but it is there:
# If not running interactively, don't do anything
[ -z "$PS1" ] && return

export HISTCONTROL=ignoreboth:erasedups
export HISTSIZE=10000
export HISTFILESIZE=10000

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

# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize

# Apaga linhas do histórico, aceitando mais de um argumento de uma vez
function histd()
    if (( $# < 1)); then
	echo 'Use assim: histd 15 14 13 12 [...]'
	echo -e "\tcom os números em ordem DECRESCENTE - ou não funciona"
    echo "history -d $1"
    echo "'$teste' devia funcionar... sqn"
    history -d $1
    while ((1)); do
	if (( $# == 0 )); then
	if (( $ult < $1 )); then
	    echo 'Sou bonzinho, mas me ajude. Desse jeito dá errado!!'
	    echo 'Use assim: histd 15 14 13 12'
	    echo -e "\t Com TODOS os números em ordem DECRESCENTE!"
	echo "history -d $1"
	history -d $1

# rmhist <primeira-linha-apagada> <última-apagada>
# -> Line numbers according to the output of history.
# -> Use history -w to force a write to the history file.
function rmhist()
    if (( $# < 1)); then
	echo 'rmhist <1a-linha-apagada> <última-linha-apagada>'
	echo -e '\tOu...'
	echo 'rmhist <quant-de-últimas-linhas-apagadas>'

    if (( $# == 1 )); then
	comeco=$(( $HISTCMD-1 ))
	if (( $1 > 10 )); then return; fi
	if (( $1 < 0 )); then return; fi
	fim=$(( $HISTCMD-$1 ))
	for (( i=$comeco; i>=$fim; i--)); do
	    echo -n $i,
	    history -d $i
    elif (( $# == 2)); then
	for (( i=$2-$1; i>=0; i--)); do
	    history -d $1
# vim: fileencoding=utf-8
.bash_logout (all of it)
# ~/.bash_logout: executed by bash(1) when login shell exits.

# when leaving the console clear the screen to increase privacy

if [ "$SHLVL" = 1 ]; then
    [ -x /usr/bin/clear_console ] && /usr/bin/clear_console -q
.bash_login does not exist

I am doing this having some terminal sessions opened, and I will not close them to make these tests. I will make a few steps to make is safe against some corruptions, if they are wrong or are potentially not enough, please say!

I assume that you are using ignoreboth to ignore commands with spaces before them => we can type commands that will not affect the history of any session.

All comments that start with #N should be made in the session number N. #1 => in session 1 and so on. Other comments are just to show other actions, like openning and closing sessions (with a ctrl+d, not with the exit command).

Some commands are intentionally started with spaces. Steps to have duplicate lines in history:

 # make a backup, in any session, of the current history.
 cp ~/.bash_history ~/.bash_history__beforeTests.2016.09.07 #save everything as is

 # open session 1
history -c #1
history -w #1
history #1 should show only these 2 last lines

 # open session 2
 history #2 note the space. Will show only the -w line
aaaa #2
bbbb #2
cccc #2
dddd #2

 # close session 2

 # open session 3
 history #3
 # Should be:
 #   1  history -w
 #   2  aaaa
 #   3  bbbb
 #   4  cccc
 #   5  dddd

 # open session 4
bbbb #4
 history #4
 # Should be:
 #   1  history -w
 #   2  aaaa
 #   3  cccc
 #   4  dddd
 #   5  bbbb

 # close session 4
 # close session 3

 # open session 5
 history #5
 # Should be:
 #   1  history -w
 #   2  aaaa
 #   3  bbbb
 #   4  cccc
 #   5  dddd
 #   6  bbbb
 # note history entries 3 and 6: both should not exist!
 # close all these sessions

 # now, in any other session, reset the history to what it
 # was before the tests were made
 cp ~/.bash_history__beforeTests.2016.09.07 ~/.bash_history
I have not tried other tests now, but I have repeated this one (to test it worked). It may not be the only way to get duplicates inserted in the history.

Now I hope that my restored backup is still there the next time I reboot my computer.

Last edited by dedec0; 09-07-2016 at 04:08 PM.
Old 09-09-2016, 07:31 AM   #19
Senior Member
Registered: May 2007
Posts: 1,081

Original Poster
Rep: Reputation: 36
Originally Posted by dedec0 View Post
Now I hope that my restored backup is still there the next time I reboot my computer.
Rebooted the computer. History is there, backup and restore worked as intended.

Now I am just waiting one solution to remove older duplicates of history lines that keeps the relative sequence of all entries.

The steps to make it contain duplicates are above, and with safe steps for anyone to test it.


bash history

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Why does BASH history command have no history when run in script ? lump_of_lard Programming 4 01-30-2015 10:45 AM
Bash history samineru Linux - Software 1 07-14-2011 07:57 AM
Bash history delete command from bash itself ashishag Linux - Software 6 05-02-2010 04:39 AM
copying a lot of files with bash or terminal. rob-n Linux - Newbie 3 04-13-2004 07:01 PM
Bash History ukndoit Linux - Security 2 10-16-2003 10:02 AM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:57 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration