Sorting to alphabetical order confuses me as I tend to look for commands grouped around a specific task. For example I'll do a number of tests on backports + no-recommends commands for a package to keep cruft to a minimum - or realise that actually a 'suggested' might have been a good idea and so add it to the command. So, I use
awk '!a[$0]++' .bash_copy > .new_bash_history
Which just cleans out duplicates and leaves the file in original order.
]]>#!/bin/bash
cat ~/.bash_history | sort -u >~/new_bash_history
mv ~/new_bash_history ~/.bash_history
As you can see it puts the file through sort with the unique option and then overwrites the old history file with the new one.
]]>Stuff you enter on the command line is all held in your .bash_history file.
You can access all those old commands by either loading that file in a text editor such as write - or you can use the 'history' command.
Just run history and then you can re-run a command just using copy and paste.
However, used with caution but even cooler, just type ! followed by the command number in the list.
I find this really handy as I merge all my old .bash_history files from wherever, clean out the junk and then make it my current file. That way I have easy access to all sorts of obscure stuff that may still be valid.
]]>