Using Bash History More Efficiently: HISTCONTROL
Using the HISTCONTROL variable you can control how bash stores your command history. You can tell it to ignore duplicate commands and/or to ignore commands that have leading whitespace.
When working at the command line we often end up executing some commands multiple times. The default history size is 500, too many duplicates of the same commands can fill up your history and leave you with a less then useful history. You can of course increase the size of your history list using HISTSIZE or HISTFILESIZE.
Another alternative is to tell bash not to store duplicates. This is done with the HISTCONTROL variable. HISTCONTROL controls how bash stores command history. Currently there are two possible flags: ignorespace and ignoredups. The ignorespace flag tells bash to ignore commands that start with spaces. The other flag, ignoredups, tells bash to ignore duplicates. You can concatenate and separate the values with a colon, ignorespace:ignoredups, if you wish to specify both values, or you can just specify ignoreboth.
You can set the flags in your ~/.bashrc file or in the global /etc/bash.bashrc file. The following command would append it to your ~/.bashrc file:
$ echo "HISTCONTROL=ignoreboth" >>~/.bashrc
Now logout and login, type some commands, try the same command numerous times. Now check your history using the up arrow or do:
$ history|more
You shouldn't see any duplicates in your history.
The history control option, ignorespace, is useful for executing commands that you don't want to record in your command history.
Cheng Renquan, Shenzhen, China
Trending Topics
| The Linux powered LAN Gaming House | Feb 08, 2012 |
| Creating a vDSO: the Colonel's Other Chicken | Feb 06, 2012 |
| Your CMS Is Not Your Web Site | Feb 01, 2012 |
| Casper, the Friendly (and Persistent) Ghost | Jan 31, 2012 |
| Razor-qt 0.4 - Qt based Desktop Environment | Jan 30, 2012 |
| Using Plop Boot Manager for USB Boot | Jan 25, 2012 |
- The Linux RAID-1, 4, 5 Code
- Readers' Choice Awards 2011
- The Linux powered LAN Gaming House
- Validate an E-Mail Address with PHP, the Right Way
- Why Python?
- Creating a vDSO: the Colonel's Other Chicken
- Building a Two-Node Linux Cluster with Heartbeat
- Python for Android
- Boot with GRUB
- Writing a Simple USB Driver
- I'll give it a whirl
3 hours 17 min ago - TFPT, don't you mean TFTP!? I
11 hours 46 min ago - wunderbar!!
12 hours 5 min ago - Best online store
16 hours 27 min ago - Best online store
16 hours 27 min ago - Best online store
16 hours 30 min ago - Best online store
16 hours 30 min ago - Best online store
16 hours 30 min ago - ----- http://ai.vc/zd
16 hours 31 min ago - Best online store
16 hours 31 min ago





Comments
you have bash 3
you can use:
export HISTCONTROL=erasedups
and you'll never have a duplicate entry in the history.
No need to log out and in
you can just do
# source ~/.bashrcinstead of logging out and in, it just saves a little time :D
Source Shortcut
Or just simply do: . ~/.bashrc
The early Unix folks must have run this command a lot.
Or even better
Add this to your ~/.bash_profile
export HISTCONTROL=ignorebothThen there's not need to set a local copy in each subshell. Each subshell would just inherit it.
Steven W. Orr