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:
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
- Readers' Choice Awards 2013
- Linux Kernel News - November 2013
- Mars Needs Women
- Sublime Text: One Editor to Rule Them All?
- RSS Feeds
- Advanced Hard Drive Caching Techniques
- December 2013 Issue of Linux Journal: Readers' Choice
- Raspberry Pi: the Perfect Home Server
- Web Administration Scripts
- New Products
- on the ground
2 hours 40 min ago
- I was able to read the whole
4 hours 9 min ago
- since i have read the title i
7 hours 29 min ago
- Belanja Online Cari Voucher Diskon
7 hours 34 min ago
- The kernel doesn't really
19 hours 45 min ago
20 hours 16 min ago
20 hours 16 min ago
22 hours 21 min ago
- This should be very helpful
23 hours 35 min ago
- As much as I share your point
1 day 1 hour ago