You are not logged in.
Thought I'd just throw this in as a reminder....
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.
Offline
I have a handy tiny little script I use to remove duplicates from my bash_history (I use the terminal a lot) and this simply removes all duplicates and sorts the history file in alphabetical order, it usually only takes a fraction of a second to complete.
#!/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.
Last edited by Dai_trying (2018-03-05 09:30)
Offline
That's neat!
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.
Offline
I've got used to having mine in alphabetical order now as I've been using this script for years but I might try your method and see how I get on, I can see it being useful to keep them in chronological order, thanks for sharing
Offline
If you want to keep duplicates out of your history, see man bash / HISTCONTROL
Offline
Thanks for that Chris, I did have ignoreboth in my bashrc but I think the better option (for me) is erasedups which I have now added.
Offline