Eliminate duplicate shell commands from history file

Jul 18, '03 09:50:00AM

Contributed by: famousactress

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.

Comments (10)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20030715164317940