If you are using Linux or a Mac these days, then you likely have bash as your default shell. It generally comes with a few nice features (tab-completion, history etc.), but there are a few tips and tricks which will make it much nicer to use. Here’s a run down of my favourite 5.
These tips are to be added to your .bashrc file. To open this use
nano ~/.bashrc
where you can replace nano with your favourite text editor (vi, emacs, pico, gedit, kate etc.)
Search through history effectively
Type control-R to start searching, then type a phrase to find it in your history. This tip isn’t advanced, but it’s a starting point that everyone should know!
history | grep "searchterm"
Will find that term in your history in a slightly more flexible way.
Improve the bash history
If you use two bash sessions at the same time, which ever you close second will write over the commands you’ve typed in the first one. That means that your history is lost for one of the sessions. Annoying to say the least. Luckily there is a way to fix this.
Open your .bashrc file as detailed above and add the lines:
shopt -s histappend
PROMPT_COMMAND='history -a'
This will append any new history to the existing file rather than rewriting it, as well as adding to the history every time the prompt is shown. Now, all your history will be saved!
Fix common spelling mistakes
In your .bashrc file, add:
shopt -s cdspell
This will ignore simple mistakes such as typing otp instead of opt, or ect instead of etc.
Remove duplicates in your history
Ever gone through your history and found that it’s mainly ls, pwd and exit? How about when typing the same command over and over, such as reading out the contents of a log file.
Adding
export HISTCONTROL="ignoredups"
export HISTIGNORE="&:ls:[bf]g:exit”
will ignore duplicate values, as well as ignoring a few common commands.
Fix multiple line commands
Add
shopt -s cmdhist
to .bashrc
This will ensure that multiple line commands stay together in your history.
Conclusion
So, 5 things that have saved me time – if you have any other tips, let me know in the comments!

Marvelous! Clear, helpful, & just what I was trying to remember.
Thanks – good to know I'm helping people out!
Thank you very much
It's helping me so much
Nice. I love the ignore dups.
This will be my first shot at editing ~/.bashrc, but I think I'm ready for it.
Great tips — I've been using bash for years, and always learn new ways to make it work better.
Nice list. I long ago created a BASH alias (maybe you should add a note about those) to do the history search:
alias hs='history | grep -i' in .bash_aliases.
Now i can search history like this “hs <command>”.
Pingback: 5 способов сделать использование bash более продуктивным at Всякие интересные штучки для WEB-разработчика
Hey any chance you might post a followup to this with a full sample .bashrc? I haven't found one I really like yet and would love to see more examples.
Thanks!
Pingback: Recipe for a better bash | adriano.ws
Thanks for this info. For those that can't install linux on there own or don't have a shell account look at this list http://on-net.info/shell-accounts/ for a free one.
nice article! nice site. you're in my rss feed now ;-)
keep it up
nice article! nice site. you're in my rss feed now ;-)
keep it up
very helpful article
You may add color to your shell , configure aliases , configure autorun bash logon scripts ,you can search through the history using ^r , you can type !! to be automatically replaced by the last command you entered … there is a ton of ways :-)
You may add color to your shell , configure aliases , configure autorun bash logon scripts ,you can search through the history using ^r , you can type !! to be automatically replaced by the last command you entered … there is a ton of ways :-)