automagically removing duplicate commands from bash history

Here is where you can post tips and tricks to share with other users of MX. Do not ask for help in this Forum.
Post Reply
Message
Author
User avatar
GDixon
Posts: 51
Joined: Fri Nov 02, 2007 4:39 pm

automagically removing duplicate commands from bash history

#1 Post by GDixon »

Does it annoy you to scroll through a ton of prior commands that are duplicates when in a terminal?

add this to your /home/"user Name/.bashrc to erase/delete duplicate commands like so.

I added it below my history size and also changed the history size to something smaller.

Code: Select all

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=50
HISTFILESIZE=2000

# erase/delete duplicates in history
HISTCONTROL=erasedups

User avatar
m_pav
Developer
Posts: 1407
Joined: Sun Aug 06, 2006 3:02 pm

Re: automagically removing duplicate commands from bash hist

#2 Post by m_pav »

Wow, I couldn't imagine having a history that only has 50 lines, I need most of what I have, but purging dupes is a great tip.
Mike P

Regd Linux User #472293
(Daily) Lenovo T560, i7-6600U, 16GB, 2.0TB SSD, MX_ahs
(ManCave) AMD FX 6100 CPU, nVidia, 8Gb, 3.25TB mixed, MX_ahs
(Spare)2017 Macbook Air 7,2, 8GB, 256GB SSD, MX_ahs

User avatar
joany
Posts: 235
Joined: Mon Feb 12, 2007 1:45 pm

Re: automagically removing duplicate commands from bash hist

#3 Post by joany »

Re: Bash command history in the terminal

How do you show that?
MX-14; 3.12-0.bpo.1-686-pae kernel using 4GB RAM
2.4GHz AMD Athlon 4600+
NVidia GeForce 6150 LE; 304.121 Display Driver
You didn't slow down because you're old; you're old because you slowed down.

User avatar
kmathern
Developer
Posts: 2406
Joined: Wed Jul 12, 2006 2:26 pm

Re: automagically removing duplicate commands from bash hist

#4 Post by kmathern »

joany wrote:Re: Bash command history in the terminal

How do you show that?
I'm assuming he's talking about the history you get when pressing the up arrow key (goes back in history), or down arrow key (goes forward). The ~/.bash_history file contains the full history. You can also search your bash history using <Ctrl>+<R>.

As far as removing the duplicates goes, I prefer to keep the entire history.

User avatar
Adrian
Developer
Posts: 8266
Joined: Wed Jul 12, 2006 1:42 am

Re: automagically removing duplicate commands from bash hist

#5 Post by Adrian »

You can also search your bash history using <Ctrl>+<R>.
That works, but I prefer to assign in ~/.inputrc the commands to arrow up and arrow down:

Code: Select all

"\e[A": history-search-backward
"\e[B": history-search-forward
I find it very convenient, I just type the beginning of the command and then arrow up, I almost never type the entire command and arrow up/down is a bit easier to use than CTRL-R. It also doesn't matter if the commands appear multiple times in the history...
Last edited by Adrian on Tue Oct 21, 2014 12:12 pm, edited 1 time in total.

User avatar
joany
Posts: 235
Joined: Mon Feb 12, 2007 1:45 pm

Re: automagically removing duplicate commands from bash hist

#6 Post by joany »

kmathern wrote:
joany wrote:Re: Bash command history in the terminal

How do you show that?
I'm assuming he's talking about the history you get when pressing the up arrow key (goes back in history), or down arrow key (goes forward). The ~/.bash_history file contains the full history. You can also search your bash history using <Ctrl>+<R>.

As far as removing the duplicates goes, I prefer to keep the entire history.
That's cool. I never knew that feature existed. Thanks!
MX-14; 3.12-0.bpo.1-686-pae kernel using 4GB RAM
2.4GHz AMD Athlon 4600+
NVidia GeForce 6150 LE; 304.121 Display Driver
You didn't slow down because you're old; you're old because you slowed down.

User avatar
GDixon
Posts: 51
Joined: Fri Nov 02, 2007 4:39 pm

Re: automagically removing duplicate commands from bash hist

#7 Post by GDixon »

I keep the normal users low but not the roots terminal, seems a bigger percentage of my bash work is in a root terminal.

User avatar
m_pav
Developer
Posts: 1407
Joined: Sun Aug 06, 2006 3:02 pm

Re: automagically removing duplicate commands from bash hist

#8 Post by m_pav »

joany wrote:How do you show that?
Type history and press return

You can also highlight a previous command and centre click anywhere in the terminal window to drop it in and press return to run it. user and root history are separated, so you won't see one from the other.
Mike P

Regd Linux User #472293
(Daily) Lenovo T560, i7-6600U, 16GB, 2.0TB SSD, MX_ahs
(ManCave) AMD FX 6100 CPU, nVidia, 8Gb, 3.25TB mixed, MX_ahs
(Spare)2017 Macbook Air 7,2, 8GB, 256GB SSD, MX_ahs

Post Reply

Return to “Tips & Tricks by users”