6

My bash history is my memory, it contains commands that I don't want to loose when I update to a newer version of Ubuntu or change my computer.

Is it possible to transfer the commands database to a fresh installation?

1
  • If it's that important, I hope you backup regularly – glenn jackman Jul 24 '15 at 17:55
11

Your bash history is saved in a plain text file, called by default .bash_history.

Unless you modified the $HISTFILE variable you should find it in your home directory:

$ echo $HISTFILE
/home/sylvain/.bash_history

If you keep your home partition when updating or reinstalling your system and if $HISTFILE is saved on this partition, there's nothing else to do.

To transfer the file to a new computer, just save it on a USB drive and replace the existing .bash_history of the target system.

If HISTTIMEFORMAT was set on the "old" system, don't forget to set it again otherwise the timestamps of the new commands won't be saved as comments in the "new" .bash_history file.

In case you would like to merge both old and new with new being saved at the end of the history file, you can use this method:

sudo apt-get install moreutils
cat .bash_history.old $HISTFILE | sponge $HISTFILE
2
  • 2
    Why 2 calls to cat? cat can read multiple files: cat .bash_history.old $HISTFILE | sponge $HISTFILE – glenn jackman Jul 24 '15 at 17:54
  • @glennjackman Absolutely, fixed. – Sylvain Pineau Jul 28 '15 at 12:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.