Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Eliminate duplicate shell commands from history file UNIX
If you're using the default terminal shell, you might be annoyed by the fact that repeating the same command with duplicate the entry in the history file. ie: If you were to type the following commands:

echo hello world
echo hello work
echo hello work
echo hello work
You would have to press the up arrow four times to get back to hello world. I do a bunch of redundant work in the terminal, so this bugs me. Here's how to fix it: edit your ~/.cshrc file and add the following line:

set histdup='all'
Restart your terminal, and you should be good to go. With this setting, all duplicate entries will be ommitted from history (run the command history to test this if you want). Note that you can also set histdup='prev' to ommit only immediate duplicates (ie it won't add the command if it was the previous command).

Hope this helps.
    •    
  • Currently 3.20 / 5
  You rated: 4 / 5 (5 votes cast)
 
[9,812 views]  

Eliminate duplicate shell commands from history file | 9 comments | Create New Account
Click here to return to the 'Eliminate duplicate shell commands from history file' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Eliminate duplicate shell commands from history file
Authored by: suthercd on Jul 18, '03 11:03:47AM

You must be using the bash shell. I found that adding this to ~/.tcshrc did the trick for me. I don't have my .tcshrc source .chsrc. Is there an advantge to doing this?

Craig



[ Reply to This | # ]
Eliminate duplicate shell commands from history file
Authored by: roast on Jul 18, '03 11:21:18AM

If you're using bash as your shell, then in ~/.bash_profile and/or ~/.bashrc, put

export HISTCONTROL=ignoredups



[ Reply to This | # ]
Eliminate duplicate shell commands from history file
Authored by: famousactress on Jul 18, '03 11:28:06AM

At the risk of sounding ignorant (which, when it comes to *X I am).. I have no idea what shell I'm using. I have a .cshrc file defined that sources /sw/bin/init.csh, and I added the set histdup='prev' to it.

Sorry if this doesn't work for everyone !



[ Reply to This | # ]
Eliminate duplicate shell commands from history file
Authored by: ashill on Jul 18, '03 12:18:50PM

If you're using OS X and you don't know, you're almost certainly using tcsh (as it's the default).

One way to check is
echo $SHELL
or run 'ps' to see which terminal processes are running.



[ Reply to This | # ]
Eliminate duplicate shell commands from history file
Authored by: famousactress on Jul 18, '03 01:02:28PM

yep.. tcsh.

thanks!



[ Reply to This | # ]
Eliminate duplicate shell commands from history file
Authored by: pckizer on Jul 19, '03 04:10:01AM

And just for those fringe power users that are using zsh, the invocation would be: 'setopt histignoredups'.



[ Reply to This | # ]
This will reset your history list
Authored by: patrickoehlinger on Jul 19, '03 04:34:17PM
I like to look up history alote. Removing duplicates (set histdup='prev') did sound good to me. But it did reset my history list. So be aware and make a backup, don't fall in the same hole as I did.
PS.: I set history = 1000 (and set savehist = 1000) so you see how much entries I lost

[ Reply to This | # ]
history list merging
Authored by: sjk on Jul 20, '03 09:27:41PM

I use:

set savehist = ($history merge)

... to merge history events to the saved history list when tcsh exits. Otherwise only the history from last shell that exits is saved, overwriting previously saved history events from other shells.

If you add "merge" the shell takes longer to exit, more noticeably on slower systems.



[ Reply to This | # ]
ACK! Danger Will Robinson!
Authored by: martinx on Jul 23, '03 05:43:15PM

Ok, using the 'all' value it might be good to point out that when it eliminates the duplicate, it eliminates the MOST CURRENT duplicate. So if you typed some long command 10 entries ago and then type it again, you can't up arrow once and expect it to be there - you have to up arrow 10 times!

It would be more convenient if the thing I just typed was only one up arrow away. I spent several days trying to figure out why my history "wasn't working" only to remember this hint. Guess I'll be using the 'prev' option from now on...



[ Reply to This | # ]