LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 07-24-2019, 09:17 AM   #1
battles
Member
 
Registered: Apr 2014
Distribution: Debian GNU/Linux 7.5 (wheezy)
Posts: 258

Rep: Reputation: Disabled
Bash question


Bash keeps a history in .bash_history. If you delete the contents in .bash_history, the history is not reset until you reboot. Is there a command whereby the history can be reset without a reboot?

To explain better what I want to do: When you hit the up button to get back to a formerly entered bash command, the up button will go through the former commands exactly as they were entered, even if a command was entered multiple times. So you have to go back through the same multiple commands again before you arrive at a command that was entered before all those identical commands. What I want is for the command to be registered only once. The .bash_history file actually contains only one of the previously entered commands, but when you are using it, it records multiple entries. Possibly there is a way to stop this multiple command recording.

Thanks

Last edited by battles; 07-24-2019 at 09:18 AM.
 
Old 07-24-2019, 09:21 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 23,501

Rep: Reputation: 6722Reputation: 6722Reputation: 6722Reputation: 6722Reputation: 6722Reputation: 6722Reputation: 6722Reputation: 6722Reputation: 6722Reputation: 6722Reputation: 6722
Quote:
Originally Posted by battles View Post
Bash keeps a history in .bash_history. If you delete the contents in .bash_history, the history is not reset until you reboot. Is there a command whereby the history can be reset without a reboot?

To explain better what I want to do: When you hit the up button to get back to a formerly entered bash command, the up button will go through the former commands exactly as they were entered, even if a command was entered multiple times. So you have to go back through the same multiple commands again before you arrive at a command that was entered before all those identical commands. What I want is for the command to be registered only once. The .bash_history file actually contains only one of the previously entered commands, but when you are using it, it records multiple entries. Possibly there is a way to stop this multiple command recording.
All you do is exit the shell; no need to reboot. Remove .bash_history, exit, then repeat that process. Those things are written to .bash_history when exiting, so if you remove it, you'll be left with what you did in that session. Do it a second time, and you'll be left with just an "exit" in the file.

There's no way (to my knowledge) to prevent the same command from being entered again in that file. You can always just sort/remove duplicates, but seems pointless to me.
 
Old 07-24-2019, 09:24 AM   #3
battles
Member
 
Registered: Apr 2014
Distribution: Debian GNU/Linux 7.5 (wheezy)
Posts: 258

Original Poster
Rep: Reputation: Disabled
Thanks. Yes, I was a bit wrong about how it worked. What I will do is write a script to remove duplicate entries bafore your instructions.
 
Old 07-24-2019, 10:49 AM   #4
battles
Member
 
Registered: Apr 2014
Distribution: Debian GNU/Linux 7.5 (wheezy)
Posts: 258

Original Poster
Rep: Reputation: Disabled
Found a way...

I found a way to stop dups from showing up when using the up key.

Place this in your .bashrc file:

export HISTCONTROL=ignoredups
 
Old 07-24-2019, 11:36 AM   #5
ehartman
Senior Member
 
Registered: Jul 2007
Location: Delft, The Netherlands
Distribution: Slackware
Posts: 1,674

Rep: Reputation: 885Reputation: 885Reputation: 885Reputation: 885Reputation: 885Reputation: 885Reputation: 885
Quote:
Originally Posted by TB0ne View Post
There's no way (to my knowledge) to prevent the same command from being entered again in that file.
This is one of the instances where bash (and shells like it) is less then tcsh:
Quote:
The histdup shell variable can be set to not save duplicate events or consecutive duplicate events.
Another is that tcsh has a separate history per shell, it is only automatic saved into a file when the variable savehist is set.
Quote:
the savehist and histfile shell variables can be set to store the history list automatically on logout and restore it on login.
and
Quote:
If the first word of the savehist shell variable is set to a number, at most that many lines are saved. If the second word of savehist is set to `merge', the history list is merged with the existing history file instead of replacing it (if there is one) and sorted by time stamp. Merging is intended for an environment like the X Window System with several shells in simultaneous use. Currently it succeeds only when the shells quit nicely one after another.
(so not if you exit the X session with multiple shells still active, you first have to exit all of the shells separately).

Last edited by ehartman; 07-24-2019 at 11:37 AM.
 
Old 07-26-2019, 01:30 PM   #6
battles
Member
 
Registered: Apr 2014
Distribution: Debian GNU/Linux 7.5 (wheezy)
Posts: 258

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by battles View Post
I found a way to stop dups from showing up when using the up key.

Place this in your .bashrc file:

export HISTCONTROL=ignoredups
Found this that works even better:

export HISTCONTROL=ignoredups:erasedups
 
  


Reply


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
Bash problem : -bash: [: /bin/bash: unary operator expected J.A.X Linux - Software 1 09-22-2011 06:52 AM
$LINENO can't be modified in bash 3.0, while it can be in bash 2.05b Darwish Linux - Software 1 11-07-2005 03:57 PM
bash my little bash alaios Linux - Newbie 4 01-11-2005 12:59 AM
bash + html + javascript or just bash ? rblampain Programming 4 12-01-2004 08:53 AM
why did bash 2.05b install delete /bin/bash & "/bin/sh -> bash"? johnpipe Linux - Software 2 06-06-2004 07:42 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:23 AM.

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