Discover and share the best of the web!
Learn more about Digg by taking the tour.
Linux Tips: take control of your bash_history
ducea.com — Here are some tricks on how you can optimize with some simple configurations settings, the usage your bash history
- 432 diggs
- digg it
- burke, on 10/12/2007, -0/+23essentially, here it is:
this goes in ~/.bash_profile or ~/.bashrc (whichever exists, usually)
export HISTCONTROL=ignoreboth
export HISTSIZE=500
histcontrol ignores dupe entries and histsize limits number of entries.
(note that the most efficent way to search your history is to hit Ctrl R and type the start of the command. It will autocomplete as soon as there's a match to a history entry, then you just hit enter)- Latka, on 10/12/2007, -0/+6And if you hit Ctrl R again, you'll cycle trough the history of that command. A time saver indeed.
- klang, on 10/12/2007, -0/+4http://mail.linux.ie/pipermail/ilug/2006-May/087799.html
suddenly bedcomes more usefull - mdxp, on 10/12/2007, -2/+2Thanks for the note. I will add your comment to my page. Thank you for getting involved.
- as2003, on 10/12/2007, -0/+2! followed by a command will execute the last line in your .bash_history that matches the command.
$ ls -lah
--snip
$ !l
--will print the same thing - EdLesMann, on 10/12/2007, -0/+1As an addendum to as2003
One of the things that I tend to use ALOT is the !#
Say I am writing and compiling code, but I am also doing other things, like moving through directories or somesuch...then the history looks something like
1 vi hello.c
2 gcc hello.c
3 cd ../
4 ls
5 cd /codebin
Here, I can now just do a !1 and edit the file again, and then !2 to recompile.
I know this is a simple example, but when your passing flags and switches and the gcc command alone is 3 lines of compiler optimizations, headers, and other various flag switches, not having to retype it again is a blessing! It is so frustrating when the compile fails because of a typo...
Anyway, I love that feature and it has to be my most used bash feature.
- lampshade, on 10/12/2007, -5/+2yeah you aren't kidding
- pyromithrandir, on 10/12/2007, -1/+3Awesome.
Finally, a Linux howto on digg that is actually useful to me. - tweakr, on 10/12/2007, -2/+4+digg
but only because burke's comment is more handy than the actual article. - Crazen, on 10/12/2007, -3/+1++burke
Otherwise it's blog spam- mdxp, on 10/12/2007, -2/+3Spam? Why do you say that?... I have written this article for my students, and as you can see there is no advertising on my site, no banners, nothing...
- Crazen, on 10/12/2007, -1/+1Sorry mdxp, I meant it's spam to go to your blog. I apologize for not adding that disclaimer.
- gdonald, on 10/12/2007, -2/+1Umm.. this box can't handle backslash033
- spc2226, on 10/12/2007, -3/+2ln -sf /dev/null ~/.bash_history
Much better - aussieaubs, on 10/12/2007, -1/+1yes toucheeee -
digg & Burkee
but only because burke's comment is more handy than the actual article. - CharlesDarwin, on 10/12/2007, -5/+2No digg. $man bash and stfu noobs.
- mdxp, on 10/12/2007, -2/+1Of course... But you should realize that not everyone knows how to do that and use some very simple tools. This was just as it said: a simple linux tip.
- burke, on 10/12/2007, -0/+1So I shouldn't bother giving you any <strikethrough>bash</strikethrough> DOS tips, because you always read the manpages from cover to cover, and therefore are familiar with every nuance?
- mdxp, on 10/12/2007, -0/+1Please go ahead and share as many tips as you want. I never said that I know everything, nor did I try to cover all the options from the manual.
- burke, on 10/12/2007, -0/+1I was just chastising the father of evolution here, no worries mdxp.
- M1Sports20, on 10/12/2007, -1/+1bash is great, but its even better if you use vi extensions (set -o vi)
- spoier, on 10/12/2007, -0/+0Yes and as we all know, bash only runs on Linux.
Psyche.- mancat, on 10/12/2007, -0/+1Digg would have you think that. Or better yet, "bash isn't the only shell? Huh?"
- cprior, on 10/12/2007, -1/+2dugg for not being Wii
- danielrm26, on 10/12/2007, -0/+1The OP should not worry about people calling this spam -- it's not. It's a helpful article that people obviously enjoyed and got something out of. It's spam only when you are rehashing *someone else's* content, not when you make your own.
And no, it's not someone else's just becaue it talks about something that's in a man page. If man pages were read by everyone then tutorials would have no use at all. The fact is, tutorials like this one are easier for most to digest than man pages -- hence this post making the front page of Digg.- mdxp, on 10/12/2007, -0/+0danielrm26, thanks for your nice words. It really helps to see that this was useful and not all the peoples are trowing flames to me like I have done something wrong...
- shakeyshakey, on 10/12/2007, -0/+0@ EdLesMann
Nice one, didn't knew that.
Great article will be prove usefull when compiling programs and such.
The comments also added alot more knowlegde.
I think this is what digg is all about - exchange of information and knowledge.
+digg
Digg is coming to a city (and computer) near you! Check out all the details on our